Hello aa,

I'd like you to do a code review.  Please execute
        g4 diff -c 8716676

or point your web browser to
        http://mondrian/8716676

to review the following code:

Change 8716676 by [EMAIL PROTECTED] on 2008/10/24 13:40:06 *pending*

        Clean up Drag-and-Drop code that is shared across platforms.
        
        PRESUBMIT=passed
        R=aa
        [EMAIL PROTECTED]
        DELTA=490  (197 added, 237 deleted, 56 changed)
        OCL=8716676

Affected files ...

... //depot/googleclient/gears/opensource/gears/Makefile#198 edit
... //depot/googleclient/gears/opensource/gears/desktop/desktop.cc#55 edit
... 
//depot/googleclient/gears/opensource/gears/desktop/drag_and_drop_registry.cc#9 
delete
... 
//depot/googleclient/gears/opensource/gears/desktop/drag_and_drop_registry.h#6 
delete
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_base.cc#1 
add
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_base.h#1 add
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_ff.cc#9 edit
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_ff.h#5 edit
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_ie.cc#8 edit
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_ie.h#6 edit

490 delta lines: 197 added, 237 deleted, 56 changed

Also consider running:
        g4 lint -c 8716676

which verifies that the changelist doesn't introduce new style violations.

If you can't do the review, please let me know as soon as possible.  During
your review, please ensure that all new code has corresponding unit tests and
that existing unit tests are updated appropriately.  Visit
http://www/eng/code_review.html for more information.

This is a semiautomated message from "g4 mail".  Complaints or suggestions?
Mail [EMAIL PROTECTED]
Change 8716676 by [EMAIL PROTECTED] on 2008/10/24 13:40:06 *pending*

        Clean up Drag-and-Drop code that is shared across platforms.
        
        OCL=8716676

Affected files ...

... //depot/googleclient/gears/opensource/gears/Makefile#198 edit
... //depot/googleclient/gears/opensource/gears/desktop/desktop.cc#55 edit
... 
//depot/googleclient/gears/opensource/gears/desktop/drag_and_drop_registry.cc#9 
delete
... 
//depot/googleclient/gears/opensource/gears/desktop/drag_and_drop_registry.h#6 
delete
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_base.cc#1 
add
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_base.h#1 add
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_ff.cc#9 edit
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_ff.h#5 edit
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_ie.cc#8 edit
... //depot/googleclient/gears/opensource/gears/desktop/drop_target_ie.h#6 edit

==== //depot/googleclient/gears/opensource/gears/Makefile#198 - 
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/Makefile ====
# action=edit type=text
--- googleclient/gears/opensource/gears/Makefile        2008-10-28 
16:50:26.000000000 +1100
+++ googleclient/gears/opensource/gears/Makefile        2008-10-28 
16:19:03.000000000 +1100
@@ -1389,7 +1389,7 @@
                desktop_test.cc \
                desktop_win32.cc \
                dll_data_wince.cc \
-               drag_and_drop_registry.cc \
+               drop_target_base.cc \
                drop_target_registration.cc \
                notification_message_orderer.cc \
                shortcut_utils_win32.cc \
==== //depot/googleclient/gears/opensource/gears/desktop/desktop.cc#55 - 
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/desktop/desktop.cc 
====
# action=edit type=text
--- googleclient/gears/opensource/gears/desktop/desktop.cc      2008-10-24 
13:25:56.000000000 +1100
+++ googleclient/gears/opensource/gears/desktop/desktop.cc      2008-10-24 
13:00:39.000000000 +1100
@@ -45,7 +45,6 @@
 #include "gears/base/safari/curl_downloader.h"
 #endif
 #include "gears/blob/blob_interface.h"
-#include "gears/desktop/drag_and_drop_registry.h"
 #include "gears/desktop/drop_target_registration.h"
 #include "gears/desktop/file_dialog.h"
 #include "gears/desktop/notification_message_orderer.h"
@@ -78,11 +77,7 @@
 #ifdef OFFICIAL_BUILD
   // The Drag-and-Drop API has not been finalized for official builds.
 #else
-#if defined(BROWSER_CHROME) ||  defined(BROWSER_WEBKIT) || \
-    defined(OS_WINCE) || defined(OS_ANDROID)
-  // The Drag-and-Drop API has not been implemented for Chrome, Safari,
-  // PocketIE, and Android.
-#else
+#if GEARS_DRAG_AND_DROP_API_IS_SUPPORTED_FOR_THIS_PLATFORM
   RegisterMethod("registerDropTarget", &GearsDesktop::RegisterDropTarget);
 #endif
 #endif  // OFFICIAL_BUILD
@@ -1025,11 +1020,7 @@
 #ifdef OFFICIAL_BUILD
 // The Drag-and-Drop API has not been finalized for official builds.
 #else
-#if defined(BROWSER_CHROME) || defined(BROWSER_WEBKIT) || \
-    defined(OS_WINCE) || defined(OS_ANDROID)
-  // The Drag-and-Drop API has not been implemented for Chrome, Safari,
-  // PocketIE, and Android.
-#else
+#if GEARS_DRAG_AND_DROP_API_IS_SUPPORTED_FOR_THIS_PLATFORM
 void GearsDesktop::RegisterDropTarget(JsCallContext *context) {
   if (EnvIsWorker()) {
     context->SetException(
@@ -1053,9 +1044,8 @@
   }
 
   std::string16 error;
-  scoped_refptr<DropTarget> drop_target(
-      DragAndDropRegistry::RegisterDropTarget(
-          this, dom_element, drag_drop_options.get(), &error));
+  scoped_refptr<DropTarget> drop_target(DropTarget::CreateDropTarget(
+      this, dom_element, drag_drop_options.get(), &error));
   if (!drop_target.get()) {
     context->SetException(error);
     return;
@@ -1064,5 +1054,5 @@
   registration->SetDropTarget(drop_target.get());
   context->SetReturnValue(JSPARAM_MODULE, registration.get());
 }
-#endif  // BROWSER_CHROME, BROWSER_WEBKIT, OS_WINCE, OS_ANDROID
+#endif  // GEARS_DRAG_AND_DROP_API_IS_SUPPORTED_FOR_THIS_PLATFORM
 #endif  // OFFICIAL_BUILD
==== 
//depot/googleclient/gears/opensource/gears/desktop/drag_and_drop_registry.cc#9 
- None ====
# action=delete type=text
==== 
//depot/googleclient/gears/opensource/gears/desktop/drag_and_drop_registry.h#6 
- None ====
# action=delete type=text
==== //depot/googleclient/gears/opensource/gears/desktop/drop_target_base.cc#1 
- 
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/desktop/drop_target_base.cc
 ====
# action=add type=text
--- /dev/null   1970-01-01 10:00:00.000000000 +1000
+++ googleclient/gears/opensource/gears/desktop/drop_target_base.cc     
2008-10-29 20:54:17.000000000 +1100
@@ -0,0 +1,95 @@
+// Copyright 2008, Google Inc.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+//  1. Redistributions of source code must retain the above copyright notice,
+//     this list of conditions and the following disclaimer.
+//  2. Redistributions in binary form must reproduce the above copyright 
notice,
+//     this list of conditions and the following disclaimer in the 
documentation
+//     and/or other materials provided with the distribution.
+//  3. Neither the name of Google Inc. nor the names of its contributors may be
+//     used to endorse or promote products derived from this software without
+//     specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifdef OFFICIAL_BUILD
+  // The Drag-and-Drop API has not been finalized for official builds.
+#else
+
+#include "gears/desktop/drop_target_base.h"
+
+#if GEARS_DRAG_AND_DROP_API_IS_SUPPORTED_FOR_THIS_PLATFORM
+
+#if BROWSER_FF
+#include "gears/desktop/drop_target_ff.h"
+#elif BROWSER_IE && !defined(OS_WINCE)
+#include "gears/desktop/drop_target_ie.h"
+#endif
+
+
+DropTargetBase::DropTargetBase()
+#ifdef DEBUG
+    : is_debugging_(false)
+#endif
+{
+}
+
+
+static bool InitializeCallback(const std::string16 name,
+                               JsObject *options,
+                               scoped_ptr<JsRootedCallback> *scoped_callback,
+                               std::string16 *error_out) {
+  JsParamType property_type = options->GetPropertyType(name);
+  if (property_type != JSPARAM_UNDEFINED &&
+      property_type != JSPARAM_FUNCTION) {
+    *error_out = STRING16(L"options.");
+    *error_out += name;
+    *error_out += STRING16(L" should be a function.");
+    return false;
+  }
+  JsRootedCallback *callback;
+  if (options->GetPropertyAsFunction(name, &callback)) {
+    scoped_callback->reset(callback);
+  }
+  return true;
+}
+
+
+bool DropTargetBase::InitializeDropTargetBase(
+    ModuleImplBaseClass *sibling_module,
+    JsDomElement &dom_element,
+    JsObject *options,
+    std::string16 *error_out) {
+  sibling_module->GetModuleEnvironment(&module_environment_);
+#ifdef DEBUG
+  if (!options->GetPropertyAsBool(STRING16(L"debug"), &is_debugging_)) {
+    is_debugging_ = false;
+  }
+#endif
+  unload_monitor_.reset(new JsEventMonitor(sibling_module->GetJsRunner(),
+                                           JSEVENT_UNLOAD,
+                                           this));
+  return InitializeCallback(STRING16(L"ondragenter"), options,
+                            &on_drag_enter_, error_out) &&
+         InitializeCallback(STRING16(L"ondragover"), options,
+                            &on_drag_over_, error_out) &&
+         InitializeCallback(STRING16(L"ondragleave"), options,
+                            &on_drag_leave_, error_out) &&
+         InitializeCallback(STRING16(L"ondrop"), options,
+                            &on_drop_, error_out);
+}
+
+
+#endif  // GEARS_DRAG_AND_DROP_API_IS_SUPPORTED_FOR_THIS_PLATFORM
+#endif  // OFFICIAL_BUILD
==== //depot/googleclient/gears/opensource/gears/desktop/drop_target_base.h#1 - 
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/desktop/drop_target_base.h
 ====
# action=add type=text
--- /dev/null   1970-01-01 10:00:00.000000000 +1000
+++ googleclient/gears/opensource/gears/desktop/drop_target_base.h      
2008-10-28 17:16:41.000000000 +1100
@@ -0,0 +1,74 @@
+// Copyright 2008, Google Inc.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+//  1. Redistributions of source code must retain the above copyright notice,
+//     this list of conditions and the following disclaimer.
+//  2. Redistributions in binary form must reproduce the above copyright 
notice,
+//     this list of conditions and the following disclaimer in the 
documentation
+//     and/or other materials provided with the distribution.
+//  3. Neither the name of Google Inc. nor the names of its contributors may be
+//     used to endorse or promote products derived from this software without
+//     specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef GEARS_DESKTOP_DROP_TARGET_BASE_H__
+#define GEARS_DESKTOP_DROP_TARGET_BASE_H__
+#ifdef OFFICIAL_BUILD
+// The Drag-and-Drop API has not been finalized for official builds.
+#else
+
+#if BROWSER_FF || (BROWSER_IE && !defined(OS_WINCE))
+
+// TODO(nigeltao): Before Drag and Drop is made an official Gears API, we have
+// to (1) implement DnD on Chrome and Safari, and (2) decide what to do about
+// mobile platforms like Android and WinCE.
+#define GEARS_DRAG_AND_DROP_API_IS_SUPPORTED_FOR_THIS_PLATFORM 1
+
+#include "gears/base/common/base_class.h"
+#include "gears/base/common/js_dom_element.h"
+#include "gears/base/common/js_runner.h"
+#include "gears/base/common/js_types.h"
+#include "gears/base/common/scoped_refptr.h"
+#include "third_party/scoped_ptr/scoped_ptr.h"
+
+class DropTargetBase
+    : public JsEventHandlerInterface{
+ public:
+  scoped_refptr<ModuleEnvironment> module_environment_;
+  scoped_ptr<JsEventMonitor> unload_monitor_;
+  scoped_ptr<JsRootedCallback> on_drag_enter_;
+  scoped_ptr<JsRootedCallback> on_drag_over_;
+  scoped_ptr<JsRootedCallback> on_drag_leave_;
+  scoped_ptr<JsRootedCallback> on_drop_;
+
+#ifdef DEBUG
+  bool is_debugging_;
+#endif
+
+  DropTargetBase();
+
+  bool InitializeDropTargetBase(ModuleImplBaseClass *sibling_module,
+                                JsDomElement &dom_element,
+                                JsObject *options,
+                                std::string16 *error_out);
+
+ private:
+  DISALLOW_EVIL_CONSTRUCTORS(DropTargetBase);
+};
+
+#endif
+
+#endif  // OFFICIAL_BUILD
+#endif  // GEARS_DESKTOP_DROP_TARGET_BASE_H__
==== //depot/googleclient/gears/opensource/gears/desktop/drop_target_ff.cc#9 - 
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/desktop/drop_target_ff.cc
 ====
# action=edit type=text
--- googleclient/gears/opensource/gears/desktop/drop_target_ff.cc       
2008-10-28 16:53:44.000000000 +1100
+++ googleclient/gears/opensource/gears/desktop/drop_target_ff.cc       
2008-10-29 20:58:02.000000000 +1100
@@ -38,7 +38,6 @@
 #include <gecko_sdk/include/nsISupportsPrimitives.h>
 #include <gecko_sdk/include/nsIURI.h>
 #include "gears/base/common/leak_counter.h"
-#include "gears/desktop/drag_and_drop_registry.h"
 #include "gears/desktop/file_dialog.h"
 
 
@@ -54,11 +53,8 @@
 NS_IMPL_ISUPPORTS1(DropTarget, nsIDOMEventListener)
 
 
-DropTarget::DropTarget() :
-#ifdef DEBUG
-    is_debugging_(false),
-#endif
-    unregister_self_has_been_called_(false) {
+DropTarget::DropTarget()
+    : unregister_self_has_been_called_(false) {
   LEAK_COUNTER_INCREMENT(DropTarget);
 }
 
@@ -88,32 +84,46 @@
 }
 
 
-void DropTarget::SetDomElement(JsDomElement &dom_element) {
-  html_element_ = dom_element.dom_html_element();
-  nsCOMPtr<nsIDOMEventTarget> event_target(do_QueryInterface(html_element_));
-  AddSelfAsEventListeners(event_target);
-  ProvideDebugVisualFeedback(false);
-}
-
-
-void DropTarget::AddSelfAsEventListeners(nsIDOMEventTarget *event_target) {
-  event_target_ = event_target;
-  AddRef();  // Balanced by a Release() call during UnregisterSelf.
-
-  if (event_target_) {
-    if (on_drag_enter_.get()) {
-      event_target_->AddEventListener(kDragEnterAsString, this, false);
-    }
-    if (on_drag_over_.get()) {
-      event_target_->AddEventListener(kDragOverAsString, this, false);
-    }
-    if (on_drag_leave_.get()) {
-      event_target_->AddEventListener(kDragExitAsString, this, false);
-    }
-    if (on_drop_.get()) {
-      event_target_->AddEventListener(kDragDropAsString, this, false);
-    }
-  }
+DropTarget *DropTarget::CreateDropTarget(ModuleImplBaseClass *sibling_module,
+                                         JsDomElement &dom_element,
+                                         JsObject *options,
+                                         std::string16 *error_out) {
+  nsCOMPtr<nsIDOMEventTarget> event_target =
+      do_QueryInterface(dom_element.dom_html_element());
+  if (!event_target) {
+    return NULL;
+  }
+
+  scoped_refptr<DropTarget> drop_target(new DropTarget);
+  if (!drop_target->InitializeDropTargetBase(sibling_module, dom_element,
+                                             options, error_out)) {
+    return NULL;
+  }
+  drop_target->event_target_ = event_target;
+  drop_target->html_element_ = dom_element.dom_html_element();
+  drop_target->AddRef();  // Balanced by a Release() call during 
UnregisterSelf.
+
+  if (event_target) {
+    if (drop_target->on_drag_enter_.get()) {
+      event_target->AddEventListener(kDragEnterAsString,
+                                     drop_target.get(), false);
+    }
+    if (drop_target->on_drag_over_.get()) {
+      event_target->AddEventListener(kDragOverAsString,
+                                     drop_target.get(), false);
+    }
+    if (drop_target->on_drag_leave_.get()) {
+      event_target->AddEventListener(kDragExitAsString,
+                                     drop_target.get(), false);
+    }
+    if (drop_target->on_drop_.get()) {
+      event_target->AddEventListener(kDragDropAsString,
+                                     drop_target.get(), false);
+    }
+  }
+
+  drop_target->ProvideDebugVisualFeedback(false);
+  return drop_target.get();
 }
 
 
@@ -138,7 +148,7 @@
     }
   }
 
-  Release();  // Balanced by an AddRef() call during AddSelfAsEventListeners.
+  Release();  // Balanced by an AddRef() call during CreateDropTarget.
 }
 
 
==== //depot/googleclient/gears/opensource/gears/desktop/drop_target_ff.h#5 - 
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/desktop/drop_target_ff.h
 ====
# action=edit type=text
--- googleclient/gears/opensource/gears/desktop/drop_target_ff.h        
2008-10-28 16:53:44.000000000 +1100
+++ googleclient/gears/opensource/gears/desktop/drop_target_ff.h        
2008-10-28 17:35:21.000000000 +1100
@@ -32,36 +32,24 @@
 #include <gecko_internal/nsIDragService.h>
 #include <gecko_internal/nsIXPConnect.h>
 #include <gecko_sdk/include/nsIDOMEventListener.h>
-#include "gears/base/common/base_class.h"
-#include "gears/base/common/js_dom_element.h"
-#include "gears/base/common/js_runner.h"
-#include "gears/base/common/js_types.h"
-#include "gears/base/common/scoped_refptr.h"
-#include "third_party/scoped_ptr/scoped_ptr.h"
+
+#include "gears/desktop/drop_target_base.h"
 
 class DropTarget
-    : public nsIDOMEventListener,
-      public JsEventHandlerInterface {
+    : public DropTargetBase,
+      public nsIDOMEventListener {
  public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMEVENTLISTENER
 
-  scoped_refptr<ModuleEnvironment> module_environment_;
-  scoped_ptr<JsEventMonitor> unload_monitor_;
-  scoped_ptr<JsRootedCallback> on_drag_enter_;
-  scoped_ptr<JsRootedCallback> on_drag_over_;
-  scoped_ptr<JsRootedCallback> on_drag_leave_;
-  scoped_ptr<JsRootedCallback> on_drop_;
-
-#ifdef DEBUG
-  bool is_debugging_;
-#endif
-
-  DropTarget();
   virtual ~DropTarget();
 
-  void SetDomElement(JsDomElement &dom_element);
-  void AddSelfAsEventListeners(nsIDOMEventTarget *event_target);
+  // The result should be held within a scoped_refptr.
+  static DropTarget *CreateDropTarget(ModuleImplBaseClass *sibling_module,
+                                      JsDomElement &dom_element,
+                                      JsObject *options,
+                                      std::string16 *error_out);
+
   void UnregisterSelf();
 
   // This is the JsEventHandlerInterface callback, not the
@@ -87,6 +75,8 @@
   nsCOMPtr<nsIXPConnect> xp_connect_;
   bool unregister_self_has_been_called_;
 
+  DropTarget();
+
   void AddEventToJsObject(JsObject *js_object, nsIDOMEvent *event);
   void ProvideDebugVisualFeedback(bool is_drag_enter);
 
==== //depot/googleclient/gears/opensource/gears/desktop/drop_target_ie.cc#8 - 
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/desktop/drop_target_ie.cc
 ====
# action=edit type=text
--- googleclient/gears/opensource/gears/desktop/drop_target_ie.cc       
2008-10-28 16:53:44.000000000 +1100
+++ googleclient/gears/opensource/gears/desktop/drop_target_ie.cc       
2008-10-28 17:26:02.000000000 +1100
@@ -35,7 +35,6 @@
 #include "gears/base/common/leak_counter.h"
 #include "gears/base/common/string16.h"
 #include "gears/base/ie/activex_utils.h"
-#include "gears/desktop/drag_and_drop_registry.h"
 #include "gears/desktop/file_dialog.h"
 
 
@@ -43,13 +42,9 @@
     { CC_STDCALL, VT_I4, 1, { VT_EMPTY } };
 
 
-DropTarget::DropTarget() :
-#ifdef DEBUG
-    is_debugging_(false),
-#endif
-    unregister_self_has_been_called_(false) {
+DropTarget::DropTarget()
+    : unregister_self_has_been_called_(false) {
   LEAK_COUNTER_INCREMENT(DropTarget);
-  Ref();  // Balanced by a Unref() call during UnregisterSelf.
 }
 
 
@@ -69,10 +64,17 @@
 }
 
   
-DropTarget *DropTarget::CreateDropTarget(JsDomElement &dom_element) {
+DropTarget *DropTarget::CreateDropTarget(ModuleImplBaseClass *sibling_module,
+                                         JsDomElement &dom_element,
+                                         JsObject *options,
+                                         std::string16 *error_out) {
   HRESULT hr;
   IDispatch *dom_element_dispatch = dom_element.dispatch();
-  scoped_ptr<DropTarget> drop_target(new DropTarget);
+  scoped_refptr<DropTarget> drop_target(new DropTarget);
+  if (!drop_target->InitializeDropTargetBase(sibling_module, dom_element,
+                                             options, error_out)) {
+    return NULL;
+  }
 
   hr = drop_target->DispEventAdvise(dom_element_dispatch,
                                     &DIID_HTMLElementEvents2);
@@ -91,8 +93,9 @@
   if (!html_document_2) { return NULL; }
   hr = html_document_2->get_parentWindow(&drop_target->html_window_2_);
   if (FAILED(hr)) { return NULL; }
-  return drop_target.release();
+  drop_target->Ref();  // Balanced by a Unref() call during UnregisterSelf.
   drop_target->ProvideDebugVisualFeedback(false);
+  return drop_target.get();
 }
 
 
@@ -300,7 +303,7 @@
   if (event_source_) {
     DispEventUnadvise(event_source_, &DIID_HTMLElementEvents2);
   }
-  Unref();  // Balanced by an Ref() call during the constructor.
+  Unref();  // Balanced by an Ref() call during CreateDropTarget.
 }
 
 
==== //depot/googleclient/gears/opensource/gears/desktop/drop_target_ie.h#6 - 
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/desktop/drop_target_ie.h
 ====
# action=edit type=text
--- googleclient/gears/opensource/gears/desktop/drop_target_ie.h        
2008-10-28 16:53:44.000000000 +1100
+++ googleclient/gears/opensource/gears/desktop/drop_target_ie.h        
2008-10-28 17:35:18.000000000 +1100
@@ -35,12 +35,7 @@
 #include <mshtmdid.h>
 #include <windows.h>
 
-#include "gears/base/common/base_class.h"
-#include "gears/base/common/js_dom_element.h"
-#include "gears/base/common/js_runner.h"
-#include "gears/base/common/js_types.h"
-#include "gears/base/common/scoped_refptr.h"
-#include "third_party/scoped_ptr/scoped_ptr.h"
+#include "gears/desktop/drop_target_base.h"
 
 // The 1 in the IDispEventSimpleImpl line is just an arbitrary positive
 // integer, as says the IDispEventSimpleImpl documentation at
@@ -62,8 +57,8 @@
 // Thus, for DropTarget's ref-counting, we use RefCounted from
 // base/common/scoped_refptr.h.
 class DropTarget
-    : public IDispEventSimpleImpl<1, DropTarget, &DIID_HTMLElementEvents2>,
-      public JsEventHandlerInterface,
+    : public DropTargetBase,
+      public IDispEventSimpleImpl<1, DropTarget, &DIID_HTMLElementEvents2>,
       public RefCounted {
  public:
   BEGIN_SINK_MAP(DropTarget)
@@ -87,19 +82,13 @@
 
   CComPtr<IHTMLWindow2> html_window_2_;
 
-  scoped_refptr<ModuleEnvironment> module_environment_;
-  scoped_ptr<JsEventMonitor> unload_monitor_;
-  scoped_ptr<JsRootedCallback> on_drag_enter_;
-  scoped_ptr<JsRootedCallback> on_drag_over_;
-  scoped_ptr<JsRootedCallback> on_drag_leave_;
-  scoped_ptr<JsRootedCallback> on_drop_;
+  virtual ~DropTarget();
 
-#ifdef DEBUG
-  bool is_debugging_;
-#endif
-
-  virtual ~DropTarget();
-  static DropTarget *CreateDropTarget(JsDomElement &dom_element);
+  // The result should be held within a scoped_refptr.
+  static DropTarget *CreateDropTarget(ModuleImplBaseClass *sibling_module,
+                                      JsDomElement &dom_element,
+                                      JsObject *options,
+                                      std::string16 *error_out);
 
   HRESULT GetHtmlDataTransfer(CComPtr<IHTMLEventObj> &html_event_obj,
                               CComPtr<IHTMLDataTransfer> &html_data_transfer);

Reply via email to