| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/browser/extensions/extension_host.h" | 5 #include "chrome/browser/extensions/extension_host.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| 11 #include "chrome/browser/browser_theme_provider.h" |
| 11 #include "chrome/browser/debugger/devtools_manager.h" | 12 #include "chrome/browser/debugger/devtools_manager.h" |
| 12 #include "chrome/browser/extensions/extension_message_service.h" | 13 #include "chrome/browser/extensions/extension_message_service.h" |
| 13 #include "chrome/browser/extensions/extension_tabs_module.h" | 14 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 14 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/renderer_host/render_view_host.h" | 16 #include "chrome/browser/renderer_host/render_view_host.h" |
| 16 #include "chrome/browser/renderer_host/render_process_host.h" | 17 #include "chrome/browser/renderer_host/render_process_host.h" |
| 17 #include "chrome/browser/renderer_host/render_widget_host.h" | 18 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 18 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 19 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 19 #include "chrome/browser/renderer_host/site_instance.h" | 20 #include "chrome/browser/renderer_host/site_instance.h" |
| 20 #include "chrome/common/bindings_policy.h" | 21 #include "chrome/common/bindings_policy.h" |
| 21 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 22 #include "chrome/common/notification_service.h" | 23 #include "chrome/common/notification_service.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/pref_service.h" | 25 #include "chrome/common/pref_service.h" |
| 25 #include "chrome/common/view_types.h" | 26 #include "chrome/common/view_types.h" |
| 26 #include "chrome/common/render_messages.h" | 27 #include "chrome/common/render_messages.h" |
| 27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 28 | 29 |
| 29 #include "grit/browser_resources.h" | 30 #include "grit/browser_resources.h" |
| 30 | 31 |
| 31 #include "webkit/glue/context_menu.h" | 32 #include "webkit/glue/context_menu.h" |
| 32 | 33 |
| 33 using WebKit::WebDragOperation; | 34 using WebKit::WebDragOperation; |
| 34 using WebKit::WebDragOperationsMask; | 35 using WebKit::WebDragOperationsMask; |
| 35 | 36 |
| 36 // static | 37 // static |
| 37 bool ExtensionHost::enable_dom_automation_ = false; | 38 bool ExtensionHost::enable_dom_automation_ = false; |
| 38 | 39 |
| 40 static const char* kToolstripTextColorSubstitution = "$TEXT_COLOR$"; |
| 41 |
| 39 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, | 42 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, |
| 40 const GURL& url, ViewType::Type host_type) | 43 const GURL& url, ViewType::Type host_type) |
| 41 : extension_(extension), | 44 : extension_(extension), |
| 42 profile_(site_instance->browsing_instance()->profile()), | 45 profile_(site_instance->browsing_instance()->profile()), |
| 43 did_stop_loading_(false), | 46 did_stop_loading_(false), |
| 44 document_element_available_(false), | 47 document_element_available_(false), |
| 45 url_(url), | 48 url_(url), |
| 46 extension_host_type_(host_type) { | 49 extension_host_type_(host_type) { |
| 47 render_view_host_ = new RenderViewHost( | 50 render_view_host_ = new RenderViewHost( |
| 48 site_instance, this, MSG_ROUTING_NONE, NULL); | 51 site_instance, this, MSG_ROUTING_NONE, NULL); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 146 |
| 144 url_ = params.url; | 147 url_ = params.url; |
| 145 if (!url_.SchemeIs(chrome::kExtensionScheme)) { | 148 if (!url_.SchemeIs(chrome::kExtensionScheme)) { |
| 146 extension_function_dispatcher_.reset(NULL); | 149 extension_function_dispatcher_.reset(NULL); |
| 147 return; | 150 return; |
| 148 } | 151 } |
| 149 extension_function_dispatcher_.reset( | 152 extension_function_dispatcher_.reset( |
| 150 new ExtensionFunctionDispatcher(render_view_host_, this, url_)); | 153 new ExtensionFunctionDispatcher(render_view_host_, this, url_)); |
| 151 } | 154 } |
| 152 | 155 |
| 153 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { | 156 void ExtensionHost::InsertCssIfToolstrip() { |
| 154 static const base::StringPiece toolstrip_css( | |
| 155 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 156 IDR_EXTENSIONS_TOOLSTRIP_CSS)); | |
| 157 #if defined(TOOLKIT_VIEWS) | 157 #if defined(TOOLKIT_VIEWS) |
| 158 ExtensionView* view = view_.get(); | 158 ExtensionView* view = view_.get(); |
| 159 if (view) { | 159 if (!view) |
| 160 // TODO(erikkay) this injection should really happen in the renderer. | 160 return; |
| 161 // When the Jerry's view type change lands, investigate moving this there. | 161 if (!view->is_toolstrip()) { |
| 162 | 162 // No CSS injecting currently, but call SetDidInsertCSS to tell the view |
| 163 // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips | 163 // that it's OK to display. |
| 164 // to blend in with the chrome UI. | 164 view->SetDidInsertCSS(true); |
| 165 if (view->is_toolstrip()) { | 165 return; |
| 166 render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string()); | |
| 167 } else { | |
| 168 // No CSS injecting currently, but call SetDidInsertCSS to tell the view | |
| 169 // that it's OK to display. | |
| 170 view->SetDidInsertCSS(true); | |
| 171 } | |
| 172 } | 166 } |
| 173 #elif defined(OS_LINUX) | 167 #elif defined(OS_LINUX) |
| 174 ExtensionViewGtk* view = view_.get(); | 168 ExtensionViewGtk* view = view_.get(); |
| 175 if (view && view->is_toolstrip()) { | 169 if (!view || !view->is_toolstrip()) |
| 176 render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string()); | 170 return; |
| 177 } | |
| 178 #endif | 171 #endif |
| 179 | 172 |
| 173 static const base::StringPiece toolstrip_css( |
| 174 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 175 IDR_EXTENSIONS_TOOLSTRIP_CSS)); |
| 176 |
| 177 std::string css = toolstrip_css.as_string(); |
| 178 ThemeProvider* theme_provider = |
| 179 render_view_host()->process()->profile()->GetThemeProvider(); |
| 180 |
| 181 SkColor text_color = theme_provider ? |
| 182 theme_provider->GetColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT) : |
| 183 SK_ColorBLACK; |
| 184 |
| 185 std::string hex_color_string = StringPrintf( |
| 186 "#%02x%02x%02x", SkColorGetR(text_color), |
| 187 SkColorGetG(text_color), |
| 188 SkColorGetB(text_color)); |
| 189 size_t pos = css.find(kToolstripTextColorSubstitution); |
| 190 while (pos != std::string::npos) { |
| 191 css.replace(pos, 12, hex_color_string); |
| 192 pos = css.find(kToolstripTextColorSubstitution); |
| 193 } |
| 194 |
| 195 #if defined(TOOLKIT_VIEWS) || defined(OS_LINUX) |
| 196 // TODO(erikkay) this injection should really happen in the renderer. |
| 197 // When the Jerry's view type change lands, investigate moving this there. |
| 198 |
| 199 // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips |
| 200 // to blend in with the chrome UI. |
| 201 render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripDefaultCss"); |
| 202 #endif |
| 203 } |
| 204 |
| 205 void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { |
| 206 InsertCssIfToolstrip(); |
| 180 if (!did_stop_loading_) { | 207 if (!did_stop_loading_) { |
| 181 NotificationService::current()->Notify( | 208 NotificationService::current()->Notify( |
| 182 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, | 209 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, |
| 183 Source<Profile>(profile_), | 210 Source<Profile>(profile_), |
| 184 Details<ExtensionHost>(this)); | 211 Details<ExtensionHost>(this)); |
| 185 did_stop_loading_ = true; | 212 did_stop_loading_ = true; |
| 186 } | 213 } |
| 187 } | 214 } |
| 188 | 215 |
| 189 void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) { | 216 void ExtensionHost::DocumentAvailableInMainFrame(RenderViewHost* rvh) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 window_id = ExtensionTabUtil::GetWindowId( | 383 window_id = ExtensionTabUtil::GetWindowId( |
| 357 const_cast<ExtensionHost* >(this)->GetBrowser()); | 384 const_cast<ExtensionHost* >(this)->GetBrowser()); |
| 358 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { | 385 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { |
| 359 // Background page is not attached to any browser window, so pass -1. | 386 // Background page is not attached to any browser window, so pass -1. |
| 360 window_id = -1; | 387 window_id = -1; |
| 361 } else { | 388 } else { |
| 362 NOTREACHED(); | 389 NOTREACHED(); |
| 363 } | 390 } |
| 364 return window_id; | 391 return window_id; |
| 365 } | 392 } |
| OLD | NEW |