]> khamidou — GitHub mirrors - electron.git/commitdiff
Use mate::Dictionary instead of base::DictionaryValue for options.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 23 Jun 2014 13:51:42 +0000 (21:51 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 23 Jun 2014 13:56:22 +0000 (21:56 +0800)
mate::Dictionary can represent arbitray type, which matches our use.

12 files changed:
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/devtools_delegate.cc
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_gtk.cc
atom/browser/native_window_gtk.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_win.cc
atom/browser/native_window_win.h
vendor/native_mate

index e0816755f9c70db62f51a2a4c75fe7561d0f902f..5a74b86bfdf0836f3f4aca54c6ac8f4bddb56c12 100644 (file)
@@ -7,7 +7,6 @@
 #include "atom/browser/api/atom_api_web_contents.h"
 #include "atom/browser/native_window.h"
 #include "atom/common/native_mate_converters/function_converter.h"
-#include "atom/common/native_mate_converters/value_converter.h"
 #include "base/bind.h"
 #include "base/callback.h"
 #include "content/public/browser/render_process_host.h"
@@ -61,7 +60,7 @@ void OnCapturePageDone(
 }  // namespace
 
 
-Window::Window(base::DictionaryValue* options)
+Window::Window(const mate::Dictionary& options)
     : window_(NativeWindow::Create(options)) {
   window_->InitFromOptions(options);
   window_->AddObserver(this);
@@ -108,10 +107,8 @@ void Window::OnRendererResponsive() {
 }
 
 // static
-mate::Wrappable* Window::New(mate::Arguments* args,
-                             const base::DictionaryValue& options) {
-  scoped_ptr<base::DictionaryValue> copied_options(options.DeepCopy());
-  return new Window(copied_options.get());
+mate::Wrappable* Window::New(const mate::Dictionary& options) {
+  return new Window(options);
 }
 
 void Window::Destroy() {
index 820651f3925361a3de5bb78446e467082c1cfc37..19d6dc55bee77b5a7d5f46d07ff697a4828eb810 100644 (file)
 
 class GURL;
 
-namespace base {
-class DictionaryValue;
-}
-
 namespace mate {
 class Arguments;
 class Dictionary;
@@ -35,8 +31,7 @@ class WebContents;
 class Window : public mate::EventEmitter,
                public NativeWindowObserver {
  public:
-  static mate::Wrappable* New(mate::Arguments* args,
-                              const base::DictionaryValue& options);
+  static mate::Wrappable* New(const mate::Dictionary& options);
 
   static void BuildPrototype(v8::Isolate* isolate,
                              v8::Handle<v8::ObjectTemplate> prototype);
@@ -44,7 +39,7 @@ class Window : public mate::EventEmitter,
   NativeWindow* window() const { return window_.get(); }
 
  protected:
-  explicit Window(base::DictionaryValue* options);
+  explicit Window(const mate::Dictionary& options);
   virtual ~Window();
 
   // Implementations of NativeWindowObserver:
index ed8dcfa3a2229d3d190730aa0247e1d47f8b654b..6981f7397d35e70c6e50b33f75c064dd0fb4b6d9 100644 (file)
@@ -7,13 +7,13 @@
 #include <string>
 
 #include "base/message_loop/message_loop.h"
-#include "base/values.h"
 #include "atom/browser/native_window.h"
 #include "content/public/browser/devtools_agent_host.h"
 #include "content/public/browser/devtools_client_host.h"
 #include "content/public/browser/devtools_http_handler.h"
 #include "content/public/browser/devtools_manager.h"
 #include "content/public/browser/web_contents.h"
+#include "native_mate/dictionary.h"
 #include "ui/gfx/point.h"
 
 namespace atom {
@@ -37,9 +37,9 @@ DevToolsDelegate::DevToolsDelegate(NativeWindow* window,
       devtools_agent_host_.get(), devtools_client_host_.get());
 
   // Go!
-  base::DictionaryValue options;
-  options.SetString("title", "DevTools Debugger");
-  window->InitFromOptions(&options);
+  mate::Dictionary options;
+  options.Set("title", "DevTools Debugger");
+  window->InitFromOptions(options);
   window->AddObserver(this);
   web_contents->GetController().LoadURL(
       GURL("chrome-devtools://devtools/devtools.html?dockSide=undocked"),
index 97a4ae515f06fe4a2b69478e102ffdbd471ff7f3..e7e320184a4438b03b813d26a6c537d19b17b7b8 100644 (file)
@@ -16,6 +16,7 @@
 #include "atom/browser/window_list.h"
 #include "atom/common/api/api_messages.h"
 #include "atom/common/atom_version.h"
+#include "atom/common/native_mate_converters/value_converter.h"
 #include "atom/common/options_switches.h"
 #include "base/command_line.h"
 #include "base/file_util.h"
@@ -39,6 +40,7 @@
 #include "content/public/browser/web_contents_view.h"
 #include "content/public/common/renderer_preferences.h"
 #include "ipc/ipc_message_macros.h"
+#include "native_mate/dictionary.h"
 #include "ui/gfx/codec/png_codec.h"
 #include "ui/gfx/point.h"
 #include "ui/gfx/rect.h"
@@ -53,7 +55,7 @@ using content::NavigationEntry;
 namespace atom {
 
 NativeWindow::NativeWindow(content::WebContents* web_contents,
-                           base::DictionaryValue* options)
+                           const mate::Dictionary& options)
     : content::WebContentsObserver(web_contents),
       has_frame_(true),
       is_closed_(false),
@@ -63,7 +65,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
       weak_factory_(this),
       inspectable_web_contents_(
           brightray::InspectableWebContents::Create(web_contents)) {
-  options->GetBoolean(switches::kFrame, &has_frame_);
+  options.Get(switches::kFrame, &has_frame_);
 
 #if defined(OS_MACOSX)
   // Temporary fix for flashing devtools, try removing this after upgraded to
@@ -73,19 +75,19 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
 
   // Read icon before window is created.
   std::string icon;
-  if (options->GetString(switches::kIcon, &icon) && !SetIcon(icon))
+  if (options.Get(switches::kIcon, &icon) && !SetIcon(icon))
     LOG(ERROR) << "Failed to set icon to " << icon;
 
   // Read iframe security before any navigation.
-  options->GetString(switches::kNodeIntegration, &node_integration_);
+  options.Get(switches::kNodeIntegration, &node_integration_);
 
   // Read the web preferences.
-  base::DictionaryValue* web_preferences;
-  if (options->GetDictionary(switches::kWebPreferences, &web_preferences))
-    web_preferences_.reset(web_preferences->DeepCopy());
+  base::DictionaryValue web_preferences;
+  if (options.Get(switches::kWebPreferences, &web_preferences))
+    web_preferences_.reset(web_preferences.DeepCopy());
 
   // Read the zoom factor before any navigation.
-  options->GetDouble(switches::kZoomFactor, &zoom_factor_);
+  options.Get(switches::kZoomFactor, &zoom_factor_);
 
   web_contents->SetDelegate(this);
   inspectable_web_contents()->SetDelegate(this);
@@ -117,15 +119,15 @@ NativeWindow::~NativeWindow() {
 }
 
 // static
-NativeWindow* NativeWindow::Create(base::DictionaryValue* options) {
+NativeWindow* NativeWindow::Create(const mate::Dictionary& options) {
   content::WebContents::CreateParams create_params(AtomBrowserContext::Get());
   return Create(content::WebContents::Create(create_params), options);
 }
 
 // static
 NativeWindow* NativeWindow::Debug(content::WebContents* web_contents) {
-  base::DictionaryValue options;
-  NativeWindow* window = NativeWindow::Create(&options);
+  mate::Dictionary options;
+  NativeWindow* window = NativeWindow::Create(options);
   window->devtools_delegate_.reset(new DevToolsDelegate(window, web_contents));
   return window;
 }
@@ -146,56 +148,55 @@ NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) {
   return NULL;
 }
 
-void NativeWindow::InitFromOptions(base::DictionaryValue* options) {
+void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
   // Setup window from options.
   int x = -1, y = -1;
   bool center;
-  if (options->GetInteger(switches::kX, &x) &&
-      options->GetInteger(switches::kY, &y)) {
+  if (options.Get(switches::kX, &x) && options.Get(switches::kY, &y)) {
     int width = -1, height = -1;
-    options->GetInteger(switches::kWidth, &width);
-    options->GetInteger(switches::kHeight, &height);
+    options.Get(switches::kWidth, &width);
+    options.Get(switches::kHeight, &height);
     Move(gfx::Rect(x, y, width, height));
-  } else if (options->GetBoolean(switches::kCenter, &center) && center) {
+  } else if (options.Get(switches::kCenter, &center) && center) {
     Center();
   }
   int min_height = -1, min_width = -1;
-  if (options->GetInteger(switches::kMinHeight, &min_height) &&
-      options->GetInteger(switches::kMinWidth, &min_width)) {
+  if (options.Get(switches::kMinHeight, &min_height) &&
+      options.Get(switches::kMinWidth, &min_width)) {
     SetMinimumSize(gfx::Size(min_width, min_height));
   }
   int max_height = -1, max_width = -1;
-  if (options->GetInteger(switches::kMaxHeight, &max_height) &&
-      options->GetInteger(switches::kMaxWidth, &max_width)) {
+  if (options.Get(switches::kMaxHeight, &max_height) &&
+      options.Get(switches::kMaxWidth, &max_width)) {
     SetMaximumSize(gfx::Size(max_width, max_height));
   }
   bool resizable;
-  if (options->GetBoolean(switches::kResizable, &resizable)) {
+  if (options.Get(switches::kResizable, &resizable)) {
     SetResizable(resizable);
   }
   bool top;
-  if (options->GetBoolean(switches::kAlwaysOnTop, &top) && top) {
+  if (options.Get(switches::kAlwaysOnTop, &top) && top) {
     SetAlwaysOnTop(true);
   }
   bool fullscreen;
-  if (options->GetBoolean(switches::kFullscreen, &fullscreen) && fullscreen) {
+  if (options.Get(switches::kFullscreen, &fullscreen) && fullscreen) {
     SetFullscreen(true);
   }
   bool skip;
-  if (options->GetBoolean(switches::kSkipTaskbar, &skip) && skip) {
+  if (options.Get(switches::kSkipTaskbar, &skip) && skip) {
     SetSkipTaskbar(skip);
   }
   bool kiosk;
-  if (options->GetBoolean(switches::kKiosk, &kiosk) && kiosk) {
+  if (options.Get(switches::kKiosk, &kiosk) && kiosk) {
     SetKiosk(kiosk);
   }
   std::string title("Atom Shell");
-  options->GetString(switches::kTitle, &title);
+  options.Get(switches::kTitle, &title);
   SetTitle(title);
 
   // Then show it.
   bool show = true;
-  options->GetBoolean(switches::kShow, &show);
+  options.Get(switches::kShow, &show);
   if (show)
     Show();
 }
index 9562d863b85b34db4b6b816ae03f5cf359ea6037..355d0b398e3d5c2092cb25629964591b2472bcaf 100644 (file)
@@ -42,6 +42,10 @@ class Rect;
 class Size;
 }
 
+namespace mate {
+class Dictionary;
+}
+
 namespace atom {
 
 class AtomJavaScriptDialogManager;
@@ -80,11 +84,11 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   // Create window with existing WebContents, the caller is responsible for
   // managing the window's live.
   static NativeWindow* Create(content::WebContents* web_contents,
-                              base::DictionaryValue* options);
+                              const mate::Dictionary& options);
 
   // Create window with new WebContents, the caller is responsible for
   // managing the window's live.
-  static NativeWindow* Create(base::DictionaryValue* options);
+  static NativeWindow* Create(const mate::Dictionary& options);
 
   // Creates a devtools window to debug the WebContents, the returned window
   // will manage its own life.
@@ -93,7 +97,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   // Find a window from its process id and routing id.
   static NativeWindow* FromRenderView(int process_id, int routing_id);
 
-  void InitFromOptions(base::DictionaryValue* options);
+  void InitFromOptions(const mate::Dictionary& options);
 
   virtual void Close() = 0;
   virtual void CloseImmediately() = 0;
@@ -198,7 +202,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
 
  protected:
   explicit NativeWindow(content::WebContents* web_contents,
-                        base::DictionaryValue* options);
+                        const mate::Dictionary& options);
 
   brightray::InspectableWebContentsImpl* inspectable_web_contents() const {
     return static_cast<brightray::InspectableWebContentsImpl*>(
index df788d28fd12bbfe81f9d74a3a066a97b8f2dcec..96a58ca89169caadefdce132d7af17f61b623143 100644 (file)
 #include "atom/common/options_switches.h"
 #include "base/environment.h"
 #include "base/nix/xdg_util.h"
-#include "base/values.h"
 #include "chrome/browser/ui/gtk/gtk_window_util.h"
 #include "content/public/browser/native_web_keyboard_event.h"
 #include "content/public/browser/web_contents.h"
 #include "content/public/browser/web_contents_view.h"
 #include "content/public/common/renderer_preferences.h"
+#include "native_mate/dictionary.h"
 #include "ui/base/accelerators/platform_accelerator_gtk.h"
 #include "ui/base/models/simple_menu_model.h"
 #include "ui/base/x/active_window_watcher_x.h"
@@ -96,7 +96,7 @@ GetRendererPreferencesSubpixelRenderingEnum(
 }  // namespace
 
 NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents,
-                                 base::DictionaryValue* options)
+                                 const mate::Dictionary& options)
     : NativeWindow(web_contents, options),
       window_(GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL))),
       vbox_(gtk_vbox_new(FALSE, 0)),
@@ -111,11 +111,11 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents,
                     GetWebContents()->GetView()->GetNativeView());
 
   int width = 800, height = 600;
-  options->GetInteger(switches::kWidth, &width);
-  options->GetInteger(switches::kHeight, &height);
+  options.Get(switches::kWidth, &width);
+  options.Get(switches::kHeight, &height);
 
   bool use_content_size = false;
-  options->GetBoolean(switches::kUseContentSize, &use_content_size);
+  options.Get(switches::kUseContentSize, &use_content_size);
   if (has_frame_ && !use_content_size)
     SubstractBorderSize(&width, &height);
 
@@ -608,7 +608,7 @@ gboolean NativeWindowGtk::OnButtonPress(GtkWidget* widget,
 
 // static
 NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
-                                   base::DictionaryValue* options) {
+                                   const mate::Dictionary& options) {
   return new NativeWindowGtk(web_contents, options);
 }
 
index 725b1d3b02cc638299d909220c2185ba341b348c..61dcdf92e9d1be1473cfee55a3e947821fe70a3e 100644 (file)
@@ -26,7 +26,7 @@ class NativeWindowGtk : public NativeWindow,
                         public ui::ActiveWindowWatcherXObserver {
  public:
   explicit NativeWindowGtk(content::WebContents* web_contents,
-                           base::DictionaryValue* options);
+                           const mate::Dictionary& options);
   virtual ~NativeWindowGtk();
 
   // NativeWindow implementation.
index c2bd8441c56f4fbbbfbf3626d0a5975a67c52121..a57b24ce9dbd62c64ed5c297266556fd484ff8f3 100644 (file)
@@ -18,7 +18,7 @@ namespace atom {
 class NativeWindowMac : public NativeWindow {
  public:
   explicit NativeWindowMac(content::WebContents* web_contents,
-                           base::DictionaryValue* options);
+                           const mate::Dictionary& options);
   virtual ~NativeWindowMac();
 
   // NativeWindow implementation.
index e3e54513f900057b736647dbb63957b6e385d277..e88491d8fd6fa3e96ab52426a5fab8db1a1029f7 100644 (file)
 #include "atom/common/options_switches.h"
 #include "base/mac/mac_util.h"
 #include "base/strings/sys_string_conversions.h"
-#include "base/values.h"
 #include "content/public/browser/native_web_keyboard_event.h"
 #include "content/public/browser/web_contents.h"
 #include "content/public/browser/web_contents_view.h"
 #include "content/public/browser/render_view_host.h"
+#include "native_mate/dictionary.h"
 #include "vendor/brightray/browser/inspectable_web_contents.h"
 #include "vendor/brightray/browser/inspectable_web_contents_view.h"
 
@@ -156,13 +156,13 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
 namespace atom {
 
 NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
-                                 base::DictionaryValue* options)
+                                 const mate::Dictionary& options)
     : NativeWindow(web_contents, options),
       is_kiosk_(false),
       attention_request_id_(0) {
   int width = 800, height = 600;
-  options->GetInteger(switches::kWidth, &width);
-  options->GetInteger(switches::kHeight, &height);
+  options.Get(switches::kWidth, &width);
+  options.Get(switches::kHeight, &height);
 
   NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
   NSRect cocoa_bounds = NSMakeRect(
@@ -193,18 +193,18 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
 
   // On OS X the initial window size doesn't include window frame.
   bool use_content_size = false;
-  options->GetBoolean(switches::kUseContentSize, &use_content_size);
+  options.Get(switches::kUseContentSize, &use_content_size);
   if (has_frame_ && !use_content_size)
     SetSize(gfx::Size(width, height));
 
   // Enable the NSView to accept first mouse event.
   bool acceptsFirstMouse = false;
-  options->GetBoolean(switches::kAcceptFirstMouse, &acceptsFirstMouse);
+  options.Get(switches::kAcceptFirstMouse, &acceptsFirstMouse);
   [delegate setAcceptsFirstMouse:acceptsFirstMouse];
 
   // Disable fullscreen button when 'fullscreen' is specified to false.
   bool fullscreen;
-  if (!(options->GetBoolean(switches::kFullscreen, &fullscreen) &&
+  if (!(options.Get(switches::kFullscreen, &fullscreen) &&
         !fullscreen)) {
     NSUInteger collectionBehavior = [window_ collectionBehavior];
     collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary;
@@ -612,7 +612,7 @@ void NativeWindowMac::UpdateDraggableRegionsForCustomDrag(
 
 // static
 NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
-                                   base::DictionaryValue* options) {
+                                   const mate::Dictionary& options) {
   return new NativeWindowMac(web_contents, options);
 }
 
index 84b26e953ad8f20ed92453506a9c07563b360cc3..4a0493c5bb81da61f2d95a42afbff089324f8416 100644 (file)
 #include "atom/common/draggable_region.h"
 #include "atom/common/options_switches.h"
 #include "base/strings/utf_string_conversions.h"
-#include "base/values.h"
 #include "base/win/scoped_comptr.h"
 #include "content/public/browser/native_web_keyboard_event.h"
 #include "content/public/browser/render_view_host.h"
 #include "content/public/browser/render_widget_host_view.h"
 #include "content/public/browser/web_contents.h"
 #include "content/public/browser/web_contents_view.h"
+#include "native_mate/dictionary.h"
 #include "ui/gfx/path.h"
 #include "ui/base/models/simple_menu_model.h"
 #include "ui/views/widget/widget.h"
@@ -217,13 +217,13 @@ class NativeWindowFramelessView : public views::NonClientFrameView {
 }  // namespace
 
 NativeWindowWin::NativeWindowWin(content::WebContents* web_contents,
-                                 base::DictionaryValue* options)
+                                 const mate::Dictionary& options)
     : NativeWindow(web_contents, options),
       window_(new views::Widget),
       web_view_(inspectable_web_contents_view()->GetView()),
       use_content_size_(false),
       resizable_(true) {
-  options->GetBoolean(switches::kResizable, &resizable_);
+  options.Get(switches::kResizable, &resizable_);
 
   views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
   params.delegate = this;
@@ -236,11 +236,11 @@ NativeWindowWin::NativeWindowWin(content::WebContents* web_contents,
   views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this);
 
   int width = 800, height = 600;
-  options->GetInteger(switches::kWidth, &width);
-  options->GetInteger(switches::kHeight, &height);
+  options.Get(switches::kWidth, &width);
+  options.Get(switches::kHeight, &height);
 
   gfx::Size size(width, height);
-  options->GetBoolean(switches::kUseContentSize, &use_content_size_);
+  options.Get(switches::kUseContentSize, &use_content_size_);
   if (has_frame_ && use_content_size_)
     ClientAreaSizeToWindowSize(&size);
 
@@ -624,7 +624,7 @@ void NativeWindowWin::RegisterAccelerators() {
 
 // static
 NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
-                                   base::DictionaryValue* options) {
+                                   const mate::Dictionary& options) {
   return new NativeWindowWin(web_contents, options);
 }
 
index 44d158e9c5a1bccf87346bd445f242d354af143d..0a5047523fac936bda7bba232b17f801f13af682 100644 (file)
@@ -35,7 +35,7 @@ class NativeWindowWin : public NativeWindow,
                         public views::WidgetDelegateView {
  public:
   explicit NativeWindowWin(content::WebContents* web_contents,
-                           base::DictionaryValue* options);
+                           const mate::Dictionary& options);
   virtual ~NativeWindowWin();
 
   // NativeWindow implementation.
index c79aecf64de260dd239c6aed8397d3e152d7589d..a5c4a2c7c64239ec5d007342f00f16f3981d6d80 160000 (submodule)
@@ -1 +1 @@
-Subproject commit c79aecf64de260dd239c6aed8397d3e152d7589d
+Subproject commit a5c4a2c7c64239ec5d007342f00f16f3981d6d80