Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/renderer/extensions/extension_helper.cc

Issue 10409088: Get rid of the RenderViewType concept in content, since it was only used by Chrome. Store the enum… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/extensions/extension_helper.h" 5 #include "chrome/renderer/extensions/extension_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/chrome_view_type.h"
16 #include "chrome/common/extensions/extension_messages.h" 15 #include "chrome/common/extensions/extension_messages.h"
17 #include "chrome/common/render_messages.h" 16 #include "chrome/common/render_messages.h"
18 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
18 #include "chrome/common/view_type.h"
19 #include "chrome/renderer/extensions/chrome_v8_context.h" 19 #include "chrome/renderer/extensions/chrome_v8_context.h"
20 #include "chrome/renderer/extensions/extension_dispatcher.h" 20 #include "chrome/renderer/extensions/extension_dispatcher.h"
21 #include "chrome/renderer/extensions/miscellaneous_bindings.h" 21 #include "chrome/renderer/extensions/miscellaneous_bindings.h"
22 #include "chrome/renderer/extensions/user_script_scheduler.h" 22 #include "chrome/renderer/extensions/user_script_scheduler.h"
23 #include "chrome/renderer/extensions/user_script_slave.h" 23 #include "chrome/renderer/extensions/user_script_slave.h"
24 #include "content/public/renderer/render_view.h" 24 #include "content/public/renderer/render_view.h"
25 #include "content/public/renderer/render_view_visitor.h" 25 #include "content/public/renderer/render_view_visitor.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
(...skipping 23 matching lines...) Expand all
52 LAZY_INSTANCE_INITIALIZER; 52 LAZY_INSTANCE_INITIALIZER;
53 53
54 // A RenderViewVisitor class that iterates through the set of available 54 // A RenderViewVisitor class that iterates through the set of available
55 // views, looking for a view of the given type, in the given browser window 55 // views, looking for a view of the given type, in the given browser window
56 // and within the given extension. 56 // and within the given extension.
57 // Used to accumulate the list of views associated with an extension. 57 // Used to accumulate the list of views associated with an extension.
58 class ExtensionViewAccumulator : public content::RenderViewVisitor { 58 class ExtensionViewAccumulator : public content::RenderViewVisitor {
59 public: 59 public:
60 ExtensionViewAccumulator(const std::string& extension_id, 60 ExtensionViewAccumulator(const std::string& extension_id,
61 int browser_window_id, 61 int browser_window_id,
62 content::ViewType view_type) 62 chrome::ViewType view_type)
63 : extension_id_(extension_id), 63 : extension_id_(extension_id),
64 browser_window_id_(browser_window_id), 64 browser_window_id_(browser_window_id),
65 view_type_(view_type) { 65 view_type_(view_type) {
66 } 66 }
67 67
68 std::vector<content::RenderView*> views() { return views_; } 68 std::vector<content::RenderView*> views() { return views_; }
69 69
70 // Returns false to terminate the iteration. 70 // Returns false to terminate the iteration.
71 virtual bool Visit(content::RenderView* render_view) { 71 virtual bool Visit(content::RenderView* render_view) {
72 ExtensionHelper* helper = ExtensionHelper::Get(render_view); 72 ExtensionHelper* helper = ExtensionHelper::Get(render_view);
(...skipping 14 matching lines...) Expand all
87 87
88 views_.push_back(render_view); 88 views_.push_back(render_view);
89 89
90 if (view_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) 90 if (view_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE)
91 return false; // There can be only one... 91 return false; // There can be only one...
92 return true; 92 return true;
93 } 93 }
94 94
95 private: 95 private:
96 // Returns true if |type| "isa" |match|. 96 // Returns true if |type| "isa" |match|.
97 static bool ViewTypeMatches(content::ViewType type, content::ViewType match) { 97 static bool ViewTypeMatches(chrome::ViewType type, chrome::ViewType match) {
98 if (type == match) 98 if (type == match)
99 return true; 99 return true;
100 100
101 // INVALID means match all. 101 // INVALID means match all.
102 if (match == content::VIEW_TYPE_INVALID) 102 if (match == chrome::VIEW_TYPE_INVALID)
103 return true; 103 return true;
104 104
105 return false; 105 return false;
106 } 106 }
107 107
108 std::string extension_id_; 108 std::string extension_id_;
109 int browser_window_id_; 109 int browser_window_id_;
110 content::ViewType view_type_; 110 chrome::ViewType view_type_;
111 std::vector<content::RenderView*> views_; 111 std::vector<content::RenderView*> views_;
112 }; 112 };
113 113
114 } 114 }
115 115
116 // static 116 // static
117 std::vector<content::RenderView*> ExtensionHelper::GetExtensionViews( 117 std::vector<content::RenderView*> ExtensionHelper::GetExtensionViews(
118 const std::string& extension_id, 118 const std::string& extension_id,
119 int browser_window_id, 119 int browser_window_id,
120 content::ViewType view_type) { 120 chrome::ViewType view_type) {
121 ExtensionViewAccumulator accumulator( 121 ExtensionViewAccumulator accumulator(
122 extension_id, browser_window_id, view_type); 122 extension_id, browser_window_id, view_type);
123 content::RenderView::ForEach(&accumulator); 123 content::RenderView::ForEach(&accumulator);
124 return accumulator.views(); 124 return accumulator.views();
125 } 125 }
126 126
127 // static 127 // static
128 content::RenderView* ExtensionHelper::GetBackgroundPage( 128 content::RenderView* ExtensionHelper::GetBackgroundPage(
129 const std::string& extension_id) { 129 const std::string& extension_id) {
130 ExtensionViewAccumulator accumulator( 130 ExtensionViewAccumulator accumulator(
131 extension_id, extension_misc::kUnknownWindowId, 131 extension_id, extension_misc::kUnknownWindowId,
132 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 132 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
133 content::RenderView::ForEach(&accumulator); 133 content::RenderView::ForEach(&accumulator);
134 CHECK_LE(accumulator.views().size(), 1u); 134 CHECK_LE(accumulator.views().size(), 1u);
135 if (accumulator.views().size() == 0) 135 if (accumulator.views().size() == 0)
136 return NULL; 136 return NULL;
137 return accumulator.views()[0]; 137 return accumulator.views()[0];
138 } 138 }
139 139
140 ExtensionHelper::ExtensionHelper(content::RenderView* render_view, 140 ExtensionHelper::ExtensionHelper(content::RenderView* render_view,
141 ExtensionDispatcher* extension_dispatcher) 141 ExtensionDispatcher* extension_dispatcher)
142 : content::RenderViewObserver(render_view), 142 : content::RenderViewObserver(render_view),
143 content::RenderViewObserverTracker<ExtensionHelper>(render_view), 143 content::RenderViewObserverTracker<ExtensionHelper>(render_view),
144 extension_dispatcher_(extension_dispatcher), 144 extension_dispatcher_(extension_dispatcher),
145 pending_app_icon_requests_(0), 145 pending_app_icon_requests_(0),
146 view_type_(content::VIEW_TYPE_INVALID), 146 view_type_(chrome::VIEW_TYPE_INVALID),
147 browser_window_id_(-1) { 147 browser_window_id_(-1) {
148 } 148 }
149 149
150 ExtensionHelper::~ExtensionHelper() { 150 ExtensionHelper::~ExtensionHelper() {
151 } 151 }
152 152
153 bool ExtensionHelper::InstallWebApplicationUsingDefinitionFile( 153 bool ExtensionHelper::InstallWebApplicationUsingDefinitionFile(
154 WebFrame* frame, string16* error) { 154 WebFrame* frame, string16* error) {
155 // There is an issue of drive-by installs with the below implementation. A web 155 // There is an issue of drive-by installs with the below implementation. A web
156 // site could force a user to install an app by timing the dialog to come up 156 // site could force a user to install an app by timing the dialog to come up
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) { 362 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
363 app_info.icons.erase(app_info.icons.begin() + i); 363 app_info.icons.erase(app_info.icons.begin() + i);
364 --i; 364 --i;
365 } 365 }
366 } 366 }
367 367
368 Send(new ExtensionHostMsg_DidGetApplicationInfo( 368 Send(new ExtensionHostMsg_DidGetApplicationInfo(
369 routing_id(), page_id, app_info)); 369 routing_id(), page_id, app_info));
370 } 370 }
371 371
372 void ExtensionHelper::OnNotifyRendererViewType(content::ViewType type) { 372 void ExtensionHelper::OnNotifyRendererViewType(chrome::ViewType type) {
373 view_type_ = type; 373 view_type_ = type;
374 } 374 }
375 375
376 void ExtensionHelper::OnUpdateBrowserWindowId(int window_id) { 376 void ExtensionHelper::OnUpdateBrowserWindowId(int window_id) {
377 browser_window_id_ = window_id; 377 browser_window_id_ = window_id;
378 } 378 }
379 379
380 void ExtensionHelper::DidDownloadApplicationDefinition( 380 void ExtensionHelper::DidDownloadApplicationDefinition(
381 const WebKit::WebURLResponse& response, 381 const WebKit::WebURLResponse& response,
382 const std::string& data) { 382 const std::string& data) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 routing_id(), *pending_app_info_)); 469 routing_id(), *pending_app_info_));
470 pending_app_info_.reset(NULL); 470 pending_app_info_.reset(NULL);
471 } 471 }
472 472
473 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { 473 void ExtensionHelper::AddErrorToRootConsole(const string16& message) {
474 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 474 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
475 render_view()->GetWebView()->mainFrame()->addMessageToConsole( 475 render_view()->GetWebView()->mainFrame()->addMessageToConsole(
476 WebConsoleMessage(WebConsoleMessage::LevelError, message)); 476 WebConsoleMessage(WebConsoleMessage::LevelError, message));
477 } 477 }
478 } 478 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698