1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/renderer/extension_helper.h"
7 #include "content/public/renderer/render_view.h"
8 #include "extensions/common/constants.h"
9 #include "extensions/common/extension_messages.h"
10 #include "extensions/common/permissions/permissions_data.h"
11 #include "extensions/common/url_pattern_set.h"
12 #include "extensions/renderer/api/automation/automation_api_helper.h"
13 #include "extensions/renderer/dispatcher.h"
14 #include "third_party/WebKit/public/platform/WebURLRequest.h"
15 #include "third_party/WebKit/public/web/WebDocument.h"
16 #include "third_party/WebKit/public/web/WebView.h"
18 namespace extensions
{
20 ExtensionHelper::ExtensionHelper(content::RenderView
* render_view
,
21 Dispatcher
* dispatcher
)
22 : content::RenderViewObserver(render_view
),
23 dispatcher_(dispatcher
) {
24 // Lifecycle managed by RenderViewObserver.
25 new AutomationApiHelper(render_view
);
28 ExtensionHelper::~ExtensionHelper() {
31 bool ExtensionHelper::OnMessageReceived(const IPC::Message
& message
) {
33 IPC_BEGIN_MESSAGE_MAP(ExtensionHelper
, message
)
34 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFrameName
, OnSetFrameName
)
35 IPC_MESSAGE_HANDLER(ExtensionMsg_AppWindowClosed
,
37 IPC_MESSAGE_UNHANDLED(handled
= false)
42 void ExtensionHelper::DraggableRegionsChanged(blink::WebFrame
* frame
) {
43 blink::WebVector
<blink::WebDraggableRegion
> webregions
=
44 frame
->document().draggableRegions();
45 std::vector
<DraggableRegion
> regions
;
46 for (size_t i
= 0; i
< webregions
.size(); ++i
) {
47 DraggableRegion region
;
48 region
.bounds
= webregions
[i
].bounds
;
49 region
.draggable
= webregions
[i
].draggable
;
50 regions
.push_back(region
);
52 Send(new ExtensionHostMsg_UpdateDraggableRegions(routing_id(), regions
));
55 void ExtensionHelper::OnSetFrameName(const std::string
& name
) {
56 blink::WebView
* web_view
= render_view()->GetWebView();
58 web_view
->mainFrame()->setName(blink::WebString::fromUTF8(name
));
61 void ExtensionHelper::OnAppWindowClosed() {
62 v8::HandleScope
scope(v8::Isolate::GetCurrent());
63 v8::Local
<v8::Context
> v8_context
=
64 render_view()->GetWebView()->mainFrame()->mainWorldScriptContext();
65 ScriptContext
* script_context
=
66 dispatcher_
->script_context_set().GetByV8Context(v8_context
);
69 script_context
->module_system()->CallModuleMethod("app.window",
73 } // namespace extensions