Cleanup code of beginFrameSubscription
authorCheng Zhao <zcbenz@gmail.com>
Sun, 26 Jun 2016 02:46:40 +0000 (11:46 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 26 Jun 2016 02:46:40 +0000 (11:46 +0900)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/frame_subscriber.cc
atom/browser/api/frame_subscriber.h
docs/api/web-contents.md

index f19ac34..e6959c8 100644 (file)
@@ -1181,15 +1181,14 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
       isolate, "Invalid event object")));
 }
 
-void WebContents::BeginFrameSubscription(
-  mate::Arguments* args) {
-  FrameSubscriber::FrameCaptureCallback callback;
+void WebContents::BeginFrameSubscription(mate::Arguments* args) {
   bool only_dirty = false;
+  FrameSubscriber::FrameCaptureCallback callback;
 
+  args->GetNext(&only_dirty);
   if (!args->GetNext(&callback)) {
-    args->GetNext(&only_dirty);
-    if (!args->GetNext(&callback))
-      args->ThrowTypeError("'callback' must be defined");
+    args->ThrowError();
+    return;
   }
 
   const auto view = web_contents()->GetRenderWidgetHostView();
index 91b6765..d6d2cf7 100644 (file)
@@ -5,8 +5,8 @@
 #include "atom/browser/api/frame_subscriber.h"
 
 #include "base/bind.h"
-#include "atom/common/node_includes.h"
 #include "atom/common/native_mate_converters/gfx_converter.h"
+#include "atom/common/node_includes.h"
 #include "content/public/browser/render_widget_host.h"
 
 namespace atom {
@@ -17,8 +17,11 @@ FrameSubscriber::FrameSubscriber(v8::Isolate* isolate,
                                  content::RenderWidgetHostView* view,
                                  const FrameCaptureCallback& callback,
                                  bool only_dirty)
-    : isolate_(isolate), view_(view), callback_(callback),
-      only_dirty_(only_dirty), weak_factory_(this) {
+    : isolate_(isolate),
+      view_(view),
+      callback_(callback),
+      only_dirty_(only_dirty),
+      weak_factory_(this) {
 }
 
 bool FrameSubscriber::ShouldCaptureFrame(
@@ -48,8 +51,9 @@ bool FrameSubscriber::ShouldCaptureFrame(
 }
 
 void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
-  const gfx::Rect& damage_rect, const SkBitmap& bitmap,
-  content::ReadbackResponse response) {
+                                       const gfx::Rect& damage_rect,
+                                       const SkBitmap& bitmap,
+                                       content::ReadbackResponse response) {
   if (response != content::ReadbackResponse::READBACK_SUCCESS)
     return;
 
@@ -67,7 +71,7 @@ void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback,
     rgb_arr_size);
 
   v8::Local<v8::Value> damage =
-    mate::Converter<gfx::Rect>::ToV8(isolate_, damage_rect);
+      mate::Converter<gfx::Rect>::ToV8(isolate_, damage_rect);
 
   callback_.Run(buffer.ToLocalChecked(), damage);
 }
index b6cff3d..0da554a 100644 (file)
@@ -21,7 +21,7 @@ namespace api {
 class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
  public:
   using FrameCaptureCallback =
-    base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
+      base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>;
 
   FrameSubscriber(v8::Isolate* isolate,
                   content::RenderWidgetHostView* view,
@@ -35,8 +35,9 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber {
 
  private:
   void OnFrameDelivered(const FrameCaptureCallback& callback,
-    const gfx::Rect& damage_rect, const SkBitmap& bitmap,
-    content::ReadbackResponse response);
+                        const gfx::Rect& damage_rect,
+                        const SkBitmap& bitmap,
+                        content::ReadbackResponse response);
 
   v8::Isolate* isolate_;
   content::RenderWidgetHostView* view_;
index c25b640..913504c 100644 (file)
@@ -921,7 +921,7 @@ For the `mouseWheel` event, the `event` object also have following properties:
 
 ### `webContents.beginFrameSubscription([onlyDirty ,]callback)`
 
-* `onlyDirty` Boolean
+* `onlyDirty` Boolean (optional) - Defaults to `false`
 * `callback` Function
 
 Begin subscribing for presentation events and captured frames, the `callback`