Add mojom for WindowOpenDisposition

Adds ui::mojom::WindowOpenDisposition and a typemap which maps it
to ::WindowOpenDisposition. This will be useful when converting
existing IPCs to mojom.

C++ references to WindowOpenDisposition are left alone for now and
we'll rely on the typemap to do its thing for Mojo messages.

Java references have been updated to use the mojom generated type
directly, removing window_open_disposition.h from the set of headers
processed by a java_cpp_enum rule.

BUG=612500

Review-Url: https://codereview.chromium.org/2363533002
Cr-Commit-Position: refs/heads/master@{#420211}
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
index 97c8fd7..d8c675b 100644
--- a/chrome/android/BUILD.gn
+++ b/chrome/android/BUILD.gn
@@ -297,6 +297,7 @@
       "//components/sync/android:sync_java",
       "//components/url_formatter/android:url_formatter_java",
       "//components/web_contents_delegate_android:web_contents_delegate_android_java",
+      "//ui/base/mojo:mojo_bindings_java",
     ]
   }
 
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java
index f5b0d27..2aee525 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java
@@ -70,8 +70,8 @@
 import org.chromium.chrome.browser.util.UrlUtilities;
 import org.chromium.content_public.browser.LoadUrlParams;
 import org.chromium.content_public.common.Referrer;
+import org.chromium.mojom.ui.mojom.WindowOpenDisposition;
 import org.chromium.net.NetworkChangeNotifier;
-import org.chromium.ui.WindowOpenDisposition;
 import org.chromium.ui.base.DeviceFormFactor;
 import org.chromium.ui.base.PageTransition;
 
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsRowAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsRowAdapter.java
index bfdcd8a..c742bc74 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsRowAdapter.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsRowAdapter.java
@@ -31,7 +31,7 @@
 import org.chromium.chrome.browser.ntp.RecentlyClosedBridge.RecentlyClosedTab;
 import org.chromium.chrome.browser.signin.SigninAccessPoint;
 import org.chromium.chrome.browser.signin.SigninAndSyncView;
-import org.chromium.ui.WindowOpenDisposition;
+import org.chromium.mojom.ui.mojom.WindowOpenDisposition;
 import org.chromium.ui.base.DeviceFormFactor;
 
 import java.util.ArrayList;
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
index deb19ca..996caaa 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java
@@ -42,7 +42,7 @@
 import org.chromium.chrome.browser.ntp.cards.ImpressionTracker;
 import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView;
 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
-import org.chromium.ui.WindowOpenDisposition;
+import org.chromium.mojom.ui.mojom.WindowOpenDisposition;
 
 import java.net.URI;
 import java.net.URISyntaxException;
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
index c064b1b..cf23182 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
@@ -102,10 +102,10 @@
 import org.chromium.content_public.common.Referrer;
 import org.chromium.content_public.common.ResourceRequestBody;
 import org.chromium.content_public.common.TopControlsState;
+import org.chromium.mojom.ui.mojom.WindowOpenDisposition;
 import org.chromium.printing.PrintManagerDelegateImpl;
 import org.chromium.printing.PrintingController;
 import org.chromium.printing.PrintingControllerImpl;
-import org.chromium.ui.WindowOpenDisposition;
 import org.chromium.ui.base.LocalizationUtils;
 import org.chromium.ui.base.PageTransition;
 import org.chromium.ui.base.ViewAndroidDelegate;
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java
index 210dea8..25a0132 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabWebContentsDelegateAndroid.java
@@ -40,7 +40,7 @@
 import org.chromium.content_public.browser.InvalidateTypes;
 import org.chromium.content_public.browser.WebContents;
 import org.chromium.content_public.common.ResourceRequestBody;
-import org.chromium.ui.WindowOpenDisposition;
+import org.chromium.mojom.ui.mojom.WindowOpenDisposition;
 
 /**
  * A basic {@link TabWebContentsDelegateAndroid} that forwards some calls to the registered
diff --git a/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/WebContentsDelegateAndroid.java b/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/WebContentsDelegateAndroid.java
index 5897fa2..fe55dce 100644
--- a/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/WebContentsDelegateAndroid.java
+++ b/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/WebContentsDelegateAndroid.java
@@ -35,9 +35,8 @@
     }
 
     /**
-     * @param disposition         The new tab disposition as per the constants in
-     *                            org.chromium.ui.WindowOpenDisposition (See
-     *                            window_open_disposition_list.h for the enumeration definitions).
+     * @param disposition         The new tab disposition, defined in
+     *                            //ui/base/mojo/window_open_disposition.mojom.
      * @param isRendererInitiated Whether or not the renderer initiated this action.
      */
     @CalledByNative
diff --git a/mojo/public/tools/bindings/chromium_bindings_configuration.gni b/mojo/public/tools/bindings/chromium_bindings_configuration.gni
index 5088557..806f4fc 100644
--- a/mojo/public/tools/bindings/chromium_bindings_configuration.gni
+++ b/mojo/public/tools/bindings/chromium_bindings_configuration.gni
@@ -20,6 +20,7 @@
   "//services/shell/public/cpp/typemaps.gni",
   "//services/ui/public/interfaces/display/typemaps.gni",
   "//skia/public/interfaces/typemaps.gni",
+  "//ui/base/mojo/typemaps.gni",
   "//ui/events/devices/mojo/typemaps.gni",
   "//ui/events/mojo/typemaps.gni",
   "//ui/gfx/typemaps.gni",
diff --git a/ui/android/BUILD.gn b/ui/android/BUILD.gn
index b6b9874..e7cfa72 100644
--- a/ui/android/BUILD.gn
+++ b/ui/android/BUILD.gn
@@ -72,7 +72,6 @@
     "../base/ime/text_input_type.h",
     "../base/page_transition_types.h",
     "../base/touch/touch_device.h",
-    "../base/window_open_disposition.h",
     "../gfx/android/java_bitmap.h",
     "resources/resource_manager.h",
     "resources/system_ui_resource_type.h",
diff --git a/ui/base/mojo/BUILD.gn b/ui/base/mojo/BUILD.gn
new file mode 100644
index 0000000..97cf160
--- /dev/null
+++ b/ui/base/mojo/BUILD.gn
@@ -0,0 +1,11 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//mojo/public/tools/bindings/mojom.gni")
+
+mojom("mojo_bindings") {
+  sources = [
+    "window_open_disposition.mojom",
+  ]
+}
diff --git a/ui/base/mojo/DEPS b/ui/base/mojo/DEPS
new file mode 100644
index 0000000..16764a92
--- /dev/null
+++ b/ui/base/mojo/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+  "+mojo/public/cpp/bindings",
+]
diff --git a/ui/base/mojo/OWNERS b/ui/base/mojo/OWNERS
new file mode 100644
index 0000000..08850f4
--- /dev/null
+++ b/ui/base/mojo/OWNERS
@@ -0,0 +1,2 @@
+per-file *.mojom=set noparent
+per-file *.mojom=file://ipc/SECURITY_OWNERS
diff --git a/ui/base/mojo/typemaps.gni b/ui/base/mojo/typemaps.gni
new file mode 100644
index 0000000..857c1cc
--- /dev/null
+++ b/ui/base/mojo/typemaps.gni
@@ -0,0 +1,5 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+typemaps = [ "//ui/base/mojo/window_open_disposition.typemap" ]
diff --git a/ui/base/mojo/window_open_disposition.mojom b/ui/base/mojo/window_open_disposition.mojom
new file mode 100644
index 0000000..ba5c876
--- /dev/null
+++ b/ui/base/mojo/window_open_disposition.mojom
@@ -0,0 +1,24 @@
+// Copyright 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+module ui.mojom;
+
+// TODO(rockot/ben): This definitely seems like the wrong layer for a
+// "window open disposition" concept. It's here to support existing uses of
+// ui::WindowOpenDisposition.
+//
+// This maps to WindowOpenDisposition in //ui/base/window_open_disposition.h.
+enum WindowOpenDisposition {
+  UNKNOWN,
+  CURRENT_TAB,
+  // Indicates that only one tab with the url should exist in the same window.
+  SINGLETON_TAB,
+  NEW_FOREGROUND_TAB,
+  NEW_BACKGROUND_TAB,
+  NEW_POPUP,
+  NEW_WINDOW,
+  SAVE_TO_DISK,
+  OFF_THE_RECORD,
+  IGNORE_ACTION,
+};
diff --git a/ui/base/mojo/window_open_disposition.typemap b/ui/base/mojo/window_open_disposition.typemap
new file mode 100644
index 0000000..9c4991d
--- /dev/null
+++ b/ui/base/mojo/window_open_disposition.typemap
@@ -0,0 +1,12 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+mojom = "//ui/base/mojo/window_open_disposition.mojom"
+public_headers = [ "//ui/base/window_open_disposition.h" ]
+public_deps = [
+  "//mojo/public/cpp/bindings",
+  "//ui/base",
+]
+traits_headers = [ "//ui/base/mojo/window_open_disposition_enum_traits.h" ]
+type_mappings = [ "ui.mojom.WindowOpenDisposition=WindowOpenDisposition" ]
diff --git a/ui/base/mojo/window_open_disposition_enum_traits.h b/ui/base/mojo/window_open_disposition_enum_traits.h
new file mode 100644
index 0000000..8c2f88c
--- /dev/null
+++ b/ui/base/mojo/window_open_disposition_enum_traits.h
@@ -0,0 +1,88 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_BASE_MOJO_WINDOW_OPEN_DISPOSITION_ENUM_TRAITS_H_
+#define UI_BASE_MOJO_WINDOW_OPEN_DISPOSITION_ENUM_TRAITS_H_
+
+#include "base/logging.h"
+#include "mojo/public/cpp/bindings/enum_traits.h"
+#include "ui/base/mojo/window_open_disposition.mojom.h"
+#include "ui/base/window_open_disposition.h"
+
+namespace mojo {
+
+template <>
+struct EnumTraits<ui::mojom::WindowOpenDisposition, WindowOpenDisposition> {
+  static ui::mojom::WindowOpenDisposition ToMojom(
+      WindowOpenDisposition disposition) {
+    switch (disposition) {
+      case WindowOpenDisposition::UNKNOWN:
+        return ui::mojom::WindowOpenDisposition::UNKNOWN;
+      case WindowOpenDisposition::CURRENT_TAB:
+        return ui::mojom::WindowOpenDisposition::CURRENT_TAB;
+      case WindowOpenDisposition::SINGLETON_TAB:
+        return ui::mojom::WindowOpenDisposition::SINGLETON_TAB;
+      case WindowOpenDisposition::NEW_FOREGROUND_TAB:
+        return ui::mojom::WindowOpenDisposition::NEW_FOREGROUND_TAB;
+      case WindowOpenDisposition::NEW_BACKGROUND_TAB:
+        return ui::mojom::WindowOpenDisposition::NEW_BACKGROUND_TAB;
+      case WindowOpenDisposition::NEW_POPUP:
+        return ui::mojom::WindowOpenDisposition::NEW_POPUP;
+      case WindowOpenDisposition::NEW_WINDOW:
+        return ui::mojom::WindowOpenDisposition::NEW_WINDOW;
+      case WindowOpenDisposition::SAVE_TO_DISK:
+        return ui::mojom::WindowOpenDisposition::SAVE_TO_DISK;
+      case WindowOpenDisposition::OFF_THE_RECORD:
+        return ui::mojom::WindowOpenDisposition::OFF_THE_RECORD;
+      case WindowOpenDisposition::IGNORE_ACTION:
+        return ui::mojom::WindowOpenDisposition::IGNORE_ACTION;
+      default:
+        NOTREACHED();
+        return ui::mojom::WindowOpenDisposition::UNKNOWN;
+    }
+  }
+
+  static bool FromMojom(ui::mojom::WindowOpenDisposition disposition,
+                        WindowOpenDisposition* out) {
+    switch (disposition) {
+      case ui::mojom::WindowOpenDisposition::UNKNOWN:
+        *out = WindowOpenDisposition::UNKNOWN;
+        return true;
+      case ui::mojom::WindowOpenDisposition::CURRENT_TAB:
+        *out = WindowOpenDisposition::CURRENT_TAB;
+        return true;
+      case ui::mojom::WindowOpenDisposition::SINGLETON_TAB:
+        *out = WindowOpenDisposition::SINGLETON_TAB;
+        return true;
+      case ui::mojom::WindowOpenDisposition::NEW_FOREGROUND_TAB:
+        *out = WindowOpenDisposition::NEW_FOREGROUND_TAB;
+        return true;
+      case ui::mojom::WindowOpenDisposition::NEW_BACKGROUND_TAB:
+        *out = WindowOpenDisposition::NEW_BACKGROUND_TAB;
+        return true;
+      case ui::mojom::WindowOpenDisposition::NEW_POPUP:
+        *out = WindowOpenDisposition::NEW_POPUP;
+        return true;
+      case ui::mojom::WindowOpenDisposition::NEW_WINDOW:
+        *out = WindowOpenDisposition::NEW_WINDOW;
+        return true;
+      case ui::mojom::WindowOpenDisposition::SAVE_TO_DISK:
+        *out = WindowOpenDisposition::SAVE_TO_DISK;
+        return true;
+      case ui::mojom::WindowOpenDisposition::OFF_THE_RECORD:
+        *out = WindowOpenDisposition::OFF_THE_RECORD;
+        return true;
+      case ui::mojom::WindowOpenDisposition::IGNORE_ACTION:
+        *out = WindowOpenDisposition::IGNORE_ACTION;
+        return true;
+      default:
+        NOTREACHED();
+        return false;
+    }
+  }
+};
+
+}  // namespace mojo
+
+#endif  // UI_BASE_MOJO_WINDOW_OPEN_DISPOSITION_ENUM_TRAITS_H_
diff --git a/ui/base/window_open_disposition.h b/ui/base/window_open_disposition.h
index f6dc4fb..f87f976 100644
--- a/ui/base/window_open_disposition.h
+++ b/ui/base/window_open_disposition.h
@@ -7,8 +7,9 @@
 
 #include "ui/base/ui_base_export.h"
 
-// A Java counterpart will be generated for this enum.
-// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui
+// DEPRECATED: Instead of introducing new references to this enum, use
+// the generated ui::mojom::WindowOpenDisposition in
+// ui/base/mojo/window_open_disposition.mojom.h.
 enum class WindowOpenDisposition {
   UNKNOWN,
   CURRENT_TAB,