Compute can_use_lcd_text using property trees.
[chromium-blink-merge.git] / extensions / renderer / extension_helper.cc
blob0ab69714e07b0342c291699a3b1a38d4587f1694
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 "content/public/renderer/render_view_visitor.h"
9 #include "extensions/common/constants.h"
10 #include "extensions/common/extension_messages.h"
11 #include "extensions/common/permissions/permissions_data.h"
12 #include "extensions/common/url_pattern_set.h"
13 #include "extensions/renderer/api/automation/automation_api_helper.h"
14 #include "extensions/renderer/console.h"
15 #include "extensions/renderer/dispatcher.h"
16 #include "third_party/WebKit/public/platform/WebURLRequest.h"
17 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
18 #include "third_party/WebKit/public/web/WebDocument.h"
19 #include "third_party/WebKit/public/web/WebLocalFrame.h"
20 #include "third_party/WebKit/public/web/WebView.h"
22 using content::ConsoleMessageLevel;
23 using blink::WebConsoleMessage;
24 using blink::WebDataSource;
25 using blink::WebFrame;
26 using blink::WebLocalFrame;
27 using blink::WebURLRequest;
28 using blink::WebView;
30 namespace extensions {
32 ExtensionHelper::ExtensionHelper(content::RenderView* render_view,
33 Dispatcher* dispatcher)
34 : content::RenderViewObserver(render_view),
35 content::RenderViewObserverTracker<ExtensionHelper>(render_view),
36 dispatcher_(dispatcher) {
37 // Lifecycle managed by RenderViewObserver.
38 new AutomationApiHelper(render_view);
41 ExtensionHelper::~ExtensionHelper() {
44 bool ExtensionHelper::OnMessageReceived(const IPC::Message& message) {
45 bool handled = true;
46 IPC_BEGIN_MESSAGE_MAP(ExtensionHelper, message)
47 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFrameName, OnSetFrameName)
48 IPC_MESSAGE_HANDLER(ExtensionMsg_AppWindowClosed,
49 OnAppWindowClosed)
50 IPC_MESSAGE_UNHANDLED(handled = false)
51 IPC_END_MESSAGE_MAP()
52 return handled;
55 void ExtensionHelper::DidCreateDocumentElement(WebLocalFrame* frame) {
56 dispatcher_->DidCreateDocumentElement(frame);
59 void ExtensionHelper::DraggableRegionsChanged(blink::WebFrame* frame) {
60 blink::WebVector<blink::WebDraggableRegion> webregions =
61 frame->document().draggableRegions();
62 std::vector<DraggableRegion> regions;
63 for (size_t i = 0; i < webregions.size(); ++i) {
64 DraggableRegion region;
65 region.bounds = webregions[i].bounds;
66 region.draggable = webregions[i].draggable;
67 regions.push_back(region);
69 Send(new ExtensionHostMsg_UpdateDraggableRegions(routing_id(), regions));
72 void ExtensionHelper::DidMatchCSS(
73 blink::WebLocalFrame* frame,
74 const blink::WebVector<blink::WebString>& newly_matching_selectors,
75 const blink::WebVector<blink::WebString>& stopped_matching_selectors) {
76 dispatcher_->DidMatchCSS(
77 frame, newly_matching_selectors, stopped_matching_selectors);
80 void ExtensionHelper::OnSetFrameName(const std::string& name) {
81 blink::WebView* web_view = render_view()->GetWebView();
82 if (web_view)
83 web_view->mainFrame()->setName(blink::WebString::fromUTF8(name));
86 void ExtensionHelper::OnAppWindowClosed() {
87 v8::HandleScope scope(v8::Isolate::GetCurrent());
88 v8::Local<v8::Context> v8_context =
89 render_view()->GetWebView()->mainFrame()->mainWorldScriptContext();
90 ScriptContext* script_context =
91 dispatcher_->script_context_set().GetByV8Context(v8_context);
92 if (!script_context)
93 return;
94 script_context->module_system()->CallModuleMethod("app.window",
95 "onAppWindowClosed");
98 } // namespace extensions