summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_function.h5
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc3
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.h7
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc78
-rw-r--r--chrome/browser/extensions/extension_tabs_module.h3
-rwxr-xr-xchrome/browser/extensions/extension_view.cc7
-rwxr-xr-xchrome/browser/extensions/extension_view.h4
-rwxr-xr-xchrome/browser/extensions/extension_view_unittest.cc6
8 files changed, 110 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h
index cc1d049..2c460eb 100644
--- a/chrome/browser/extensions/extension_function.h
+++ b/chrome/browser/extensions/extension_function.h
@@ -71,8 +71,11 @@ class ExtensionFunction {
// returning. The calling renderer process will be killed.
bool bad_message_;
- private:
+ // The dispatcher that will service this extension function call.
ExtensionFunctionDispatcher* dispatcher_;
+
+ private:
+ // Id of js function to callback upon completion. -1 represents no callback.
int callback_id_;
DISALLOW_COPY_AND_ASSIGN(ExtensionFunction);
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index 6545f6f..5ca347b 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -52,6 +52,7 @@ FactoryRegistry::FactoryRegistry() {
// Tabs
factories_["GetWindows"] = &NewExtensionFunction<GetWindowsFunction>;
+ factories_["CreateWindow"] = &NewExtensionFunction<CreateWindowFunction>;
factories_["GetTabsForWindow"] =
&NewExtensionFunction<GetTabsForWindowFunction>;
factories_["GetTab"] = &NewExtensionFunction<GetTabFunction>;
@@ -97,8 +98,10 @@ void ExtensionFunctionDispatcher::GetAllFunctionNames(
ExtensionFunctionDispatcher::ExtensionFunctionDispatcher(
RenderViewHost* render_view_host,
+ Browser* browser,
const std::string& extension_id)
: render_view_host_(render_view_host),
+ browser_(browser),
extension_id_(extension_id) {
}
diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h
index ab3a07d..1ffb3d4 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.h
+++ b/chrome/browser/extensions/extension_function_dispatcher.h
@@ -10,9 +10,11 @@
#include "base/values.h"
+class Browser;
class ExtensionFunction;
class Profile;
class RenderViewHost;
+class RenderViewHostDelegate;
// ExtensionFunctionDispatcher receives requests to execute functions from
// Chromium extensions running in a RenderViewHost and dispatches them to the
@@ -23,6 +25,7 @@ class ExtensionFunctionDispatcher {
static void GetAllFunctionNames(std::vector<std::string>* names);
ExtensionFunctionDispatcher(RenderViewHost* render_view_host,
+ Browser* browser,
const std::string& extension_id);
// Handle a request to execute an extension function.
@@ -32,6 +35,8 @@ class ExtensionFunctionDispatcher {
// Send a response to a function.
void SendResponse(ExtensionFunction* api);
+ Browser* browser() { return browser_; }
+
// Handle a malformed message. Possibly the result of an attack, so kill
// the renderer.
void HandleBadMessage(ExtensionFunction* api);
@@ -45,6 +50,8 @@ class ExtensionFunctionDispatcher {
private:
RenderViewHost* render_view_host_;
+ Browser* browser_;
+
std::string extension_id_;
};
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 278ebd7..67f4cc6 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -8,8 +8,16 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
+#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
+// TODO(port): Port these files.
+#if defined(OS_WIN)
+#include "chrome/browser/window_sizer.h"
+#else
+#include "chrome/common/temp_scaffolding_stubs.h"
+#endif
+
// Forward declare static helper functions defined below.
static DictionaryValue* CreateWindowValue(Browser* browser);
static ListValue* CreateTabList(Browser* browser);
@@ -72,6 +80,72 @@ bool GetWindowsFunction::RunImpl() {
return true;
}
+bool CreateWindowFunction::RunImpl() {
+ scoped_ptr<GURL> url(new GURL());
+
+ // Look for optional url.
+ if (args_->IsType(Value::TYPE_DICTIONARY)) {
+ const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
+ std::string url_input;
+ if (args->GetString(L"url", &url_input)) {
+ url.reset(new GURL(url_input));
+ if (!url->is_valid()) {
+ // TODO(rafaelw): need error message/callback here
+ return false;
+ }
+ }
+ }
+
+ // Try to get the browser associated with view that this call came from, so
+ // its position can be set relative to its browser window.
+ Browser* browser = dispatcher_->browser();
+ if (browser == NULL)
+ browser = BrowserList::GetLastActiveWithProfile(dispatcher_->profile());
+
+ // Try to position the new browser relative its originating browser window.
+ gfx::Rect empty_bounds;
+ gfx::Rect bounds;
+ bool maximized;
+ // The call offsets the bounds by kWindowTilePixels (defined in WindowSizer to
+ // be 10).
+ WindowSizer::GetBrowserWindowBounds(std::wstring(), empty_bounds, browser,
+ &bounds, &maximized);
+
+ // Any part of the bounds can optionally be set by the caller.
+ if (args_->IsType(Value::TYPE_DICTIONARY)) {
+ const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
+ int bounds_val;
+ if (args->GetInteger(L"left", &bounds_val))
+ bounds.set_x(bounds_val);
+
+ if (args->GetInteger(L"top", &bounds_val))
+ bounds.set_y(bounds_val);
+
+ if (args->GetInteger(L"width", &bounds_val))
+ bounds.set_width(bounds_val);
+
+ if (args->GetInteger(L"height", &bounds_val))
+ bounds.set_height(bounds_val);
+ }
+
+ Browser *new_window = Browser::Create(dispatcher_->profile());
+ if (url->is_valid()) {
+ new_window->AddTabWithURL(*(url.get()),
+ GURL(), PageTransition::LINK,
+ true, -1, NULL);
+ } else {
+ new_window->NewTab();
+ }
+ new_window->window()->SetBounds(bounds);
+ new_window->window()->Show();
+
+ // TODO(rafaelw): support |focused|, |zIndex|
+
+ result_.reset(CreateWindowValue(new_window));
+
+ return true;
+}
+
bool GetTabsForWindowFunction::RunImpl() {
if (!args_->IsType(Value::TYPE_NULL))
return false;
@@ -123,7 +197,7 @@ bool CreateTabFunction::RunImpl() {
}
TabContents* contents = browser->AddTabWithURL(GURL(url), GURL(),
- PageTransition::TYPED, selected, index, NULL);
+ PageTransition::LINK, selected, index, NULL);
index = tab_strip->GetIndexOfTabContents(contents);
// Return data about the newly created tab.
@@ -186,7 +260,7 @@ bool UpdateTabFunction::RunImpl() {
if (args->GetString(L"url", &url)) {
GURL new_gurl(url);
if (new_gurl.is_valid()) {
- controller.LoadURL(new_gurl, GURL(), PageTransition::TYPED);
+ controller.LoadURL(new_gurl, GURL(), PageTransition::LINK);
} else {
// TODO(rafaelw): return some reasonable error?
}
diff --git a/chrome/browser/extensions/extension_tabs_module.h b/chrome/browser/extensions/extension_tabs_module.h
index 5abfab8..617fcf9 100644
--- a/chrome/browser/extensions/extension_tabs_module.h
+++ b/chrome/browser/extensions/extension_tabs_module.h
@@ -20,6 +20,9 @@ class ExtensionTabUtil {
class GetWindowsFunction : public SyncExtensionFunction {
virtual bool RunImpl();
};
+class CreateWindowFunction : public SyncExtensionFunction {
+ virtual bool RunImpl();
+};
class GetTabsForWindowFunction : public SyncExtensionFunction {
virtual bool RunImpl();
};
diff --git a/chrome/browser/extensions/extension_view.cc b/chrome/browser/extensions/extension_view.cc
index a26194c..2332886 100755
--- a/chrome/browser/extensions/extension_view.cc
+++ b/chrome/browser/extensions/extension_view.cc
@@ -39,6 +39,13 @@ ExtensionView::ExtensionView(Extension* extension,
pending_preferred_width_(0) {
}
+ExtensionFunctionDispatcher* ExtensionView::
+ CreateExtensionFunctionDispatcher(RenderViewHost *render_view_host,
+ const std::string& extension_id) {
+ return new ExtensionFunctionDispatcher(render_view_host, browser_,
+ extension_id);
+}
+
void ExtensionView::ShowIfCompletelyLoaded() {
// We wait to show the ExtensionView until it has loaded and our parent has
// given us a background. These can happen in different orders.
diff --git a/chrome/browser/extensions/extension_view.h b/chrome/browser/extensions/extension_view.h
index 51c84a3..429f89f 100755
--- a/chrome/browser/extensions/extension_view.h
+++ b/chrome/browser/extensions/extension_view.h
@@ -18,6 +18,7 @@
class Browser;
class Extension;
+class ExtensionFunctionDispatcher;
class RenderWidgetHost;
class RenderWidgetHostView;
class WebContents;
@@ -47,6 +48,9 @@ class ExtensionView : public HWNDHtmlView,
// RenderViewHostDelegate
// TODO(mpcomplete): GetProfile is unused.
virtual Profile* GetProfile() const { return NULL; }
+ virtual ExtensionFunctionDispatcher *CreateExtensionFunctionDispatcher(
+ RenderViewHost *render_view_host,
+ const std::string& extension_id);
virtual void RenderViewCreated(RenderViewHost* render_view_host);
virtual void DidContentsPreferredWidthChange(const int pref_width);
virtual void DidStopLoading(RenderViewHost* render_view_host,
diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_view_unittest.cc
index e493421..e1c3d8d 100755
--- a/chrome/browser/extensions/extension_view_unittest.cc
+++ b/chrome/browser/extensions/extension_view_unittest.cc
@@ -39,6 +39,12 @@ class MockExtensionView : public ExtensionView {
ui_test_utils::RunMessageLoop();
}
+ virtual ExtensionFunctionDispatcher* CreateExtensionFunctionDispatcher(
+ RenderViewHost* render_view_host) {
+ NOTREACHED();
+ return NULL;
+ }
+
bool got_message() { return got_message_; }
private:
virtual void RunJavaScriptMessage(