| OLD | NEW |
| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 32 #include "webkit/glue/image_resource_fetcher.h" | 32 #include "webkit/glue/image_resource_fetcher.h" |
| 33 #include "webkit/glue/resource_fetcher.h" | 33 #include "webkit/glue/resource_fetcher.h" |
| 34 | 34 |
| 35 using content::ConsoleMessageLevel; |
| 35 using extensions::MiscellaneousBindings; | 36 using extensions::MiscellaneousBindings; |
| 36 using WebKit::WebConsoleMessage; | 37 using WebKit::WebConsoleMessage; |
| 37 using WebKit::WebDataSource; | 38 using WebKit::WebDataSource; |
| 38 using WebKit::WebFrame; | 39 using WebKit::WebFrame; |
| 39 using WebKit::WebURLRequest; | 40 using WebKit::WebURLRequest; |
| 40 using WebKit::WebScopedUserGesture; | 41 using WebKit::WebScopedUserGesture; |
| 41 using WebKit::WebView; | 42 using WebKit::WebView; |
| 42 using webkit_glue::ImageResourceFetcher; | 43 using webkit_glue::ImageResourceFetcher; |
| 43 using webkit_glue::ResourceFetcher; | 44 using webkit_glue::ResourceFetcher; |
| 44 | 45 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) | 209 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) |
| 209 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, | 210 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, |
| 210 OnExtensionDispatchOnDisconnect) | 211 OnExtensionDispatchOnDisconnect) |
| 211 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) | 212 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) |
| 212 IPC_MESSAGE_HANDLER(ExtensionMsg_GetApplicationInfo, OnGetApplicationInfo) | 213 IPC_MESSAGE_HANDLER(ExtensionMsg_GetApplicationInfo, OnGetApplicationInfo) |
| 213 IPC_MESSAGE_HANDLER(ExtensionMsg_SetTabId, OnSetTabId) | 214 IPC_MESSAGE_HANDLER(ExtensionMsg_SetTabId, OnSetTabId) |
| 214 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateBrowserWindowId, | 215 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateBrowserWindowId, |
| 215 OnUpdateBrowserWindowId) | 216 OnUpdateBrowserWindowId) |
| 216 IPC_MESSAGE_HANDLER(ExtensionMsg_NotifyRenderViewType, | 217 IPC_MESSAGE_HANDLER(ExtensionMsg_NotifyRenderViewType, |
| 217 OnNotifyRendererViewType) | 218 OnNotifyRendererViewType) |
| 219 IPC_MESSAGE_HANDLER(ExtensionMsg_AddMessageToConsole, |
| 220 OnAddMessageToConsole) |
| 218 IPC_MESSAGE_UNHANDLED(handled = false) | 221 IPC_MESSAGE_UNHANDLED(handled = false) |
| 219 IPC_END_MESSAGE_MAP() | 222 IPC_END_MESSAGE_MAP() |
| 220 return handled; | 223 return handled; |
| 221 } | 224 } |
| 222 | 225 |
| 223 void ExtensionHelper::DidFinishDocumentLoad(WebFrame* frame) { | 226 void ExtensionHelper::DidFinishDocumentLoad(WebFrame* frame) { |
| 224 extension_dispatcher_->user_script_slave()->InjectScripts( | 227 extension_dispatcher_->user_script_slave()->InjectScripts( |
| 225 frame, UserScript::DOCUMENT_END); | 228 frame, UserScript::DOCUMENT_END); |
| 226 | 229 |
| 227 SchedulerMap::iterator i = g_schedulers.Get().find(frame); | 230 SchedulerMap::iterator i = g_schedulers.Get().find(frame); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 void ExtensionHelper::OnSetTabId(int init_tab_id) { | 381 void ExtensionHelper::OnSetTabId(int init_tab_id) { |
| 379 CHECK_EQ(tab_id_, -1); | 382 CHECK_EQ(tab_id_, -1); |
| 380 CHECK_GE(init_tab_id, 0); | 383 CHECK_GE(init_tab_id, 0); |
| 381 tab_id_ = init_tab_id; | 384 tab_id_ = init_tab_id; |
| 382 } | 385 } |
| 383 | 386 |
| 384 void ExtensionHelper::OnUpdateBrowserWindowId(int window_id) { | 387 void ExtensionHelper::OnUpdateBrowserWindowId(int window_id) { |
| 385 browser_window_id_ = window_id; | 388 browser_window_id_ = window_id; |
| 386 } | 389 } |
| 387 | 390 |
| 391 void ExtensionHelper::OnAddMessageToConsole(ConsoleMessageLevel level, |
| 392 const std::string& message) { |
| 393 AddMessageToRootConsole(level, UTF8ToUTF16(message)); |
| 394 } |
| 395 |
| 388 void ExtensionHelper::DidDownloadApplicationDefinition( | 396 void ExtensionHelper::DidDownloadApplicationDefinition( |
| 389 const WebKit::WebURLResponse& response, | 397 const WebKit::WebURLResponse& response, |
| 390 const std::string& data) { | 398 const std::string& data) { |
| 391 scoped_ptr<WebApplicationInfo> app_info( | 399 scoped_ptr<WebApplicationInfo> app_info( |
| 392 pending_app_info_.release()); | 400 pending_app_info_.release()); |
| 393 | 401 |
| 394 JSONStringValueSerializer serializer(data); | 402 JSONStringValueSerializer serializer(data); |
| 395 int error_code = 0; | 403 int error_code = 0; |
| 396 std::string error_message; | 404 std::string error_message; |
| 397 scoped_ptr<Value> result(serializer.Deserialize(&error_code, &error_message)); | 405 scoped_ptr<Value> result(serializer.Deserialize(&error_code, &error_message)); |
| 398 if (!result.get()) { | 406 if (!result.get()) { |
| 399 AddErrorToRootConsole(UTF8ToUTF16(error_message)); | 407 AddMessageToRootConsole( |
| 408 content::CONSOLE_MESSAGE_LEVEL_ERROR, UTF8ToUTF16(error_message)); |
| 400 return; | 409 return; |
| 401 } | 410 } |
| 402 | 411 |
| 403 string16 error_message_16; | 412 string16 error_message_16; |
| 404 if (!web_apps::ParseWebAppFromDefinitionFile(result.get(), app_info.get(), | 413 if (!web_apps::ParseWebAppFromDefinitionFile(result.get(), app_info.get(), |
| 405 &error_message_16)) { | 414 &error_message_16)) { |
| 406 AddErrorToRootConsole(error_message_16); | 415 AddMessageToRootConsole( |
| 416 content::CONSOLE_MESSAGE_LEVEL_ERROR, error_message_16); |
| 407 return; | 417 return; |
| 408 } | 418 } |
| 409 | 419 |
| 410 if (!app_info->icons.empty()) { | 420 if (!app_info->icons.empty()) { |
| 411 pending_app_info_.reset(app_info.release()); | 421 pending_app_info_.reset(app_info.release()); |
| 412 pending_app_icon_requests_ = | 422 pending_app_icon_requests_ = |
| 413 static_cast<int>(pending_app_info_->icons.size()); | 423 static_cast<int>(pending_app_info_->icons.size()); |
| 414 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) { | 424 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) { |
| 415 app_icon_fetchers_.push_back(linked_ptr<ImageResourceFetcher>( | 425 app_icon_fetchers_.push_back(linked_ptr<ImageResourceFetcher>( |
| 416 new ImageResourceFetcher( | 426 new ImageResourceFetcher( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 // want to start allowing larger icons (see bug 63406), we'll have to either | 469 // want to start allowing larger icons (see bug 63406), we'll have to either |
| 460 // experiment mor ewith this and find the real limit, or else come up with | 470 // experiment mor ewith this and find the real limit, or else come up with |
| 461 // some alternative way to transmit the icon data to the browser process. | 471 // some alternative way to transmit the icon data to the browser process. |
| 462 // | 472 // |
| 463 // See also: bug 63729. | 473 // See also: bug 63729. |
| 464 const size_t kMaxIconSize = 1024 * 128; | 474 const size_t kMaxIconSize = 1024 * 128; |
| 465 size_t actual_icon_size = 0; | 475 size_t actual_icon_size = 0; |
| 466 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) { | 476 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) { |
| 467 size_t current_size = pending_app_info_->icons[i].data.getSize(); | 477 size_t current_size = pending_app_info_->icons[i].data.getSize(); |
| 468 if (current_size > kMaxIconSize - actual_icon_size) { | 478 if (current_size > kMaxIconSize - actual_icon_size) { |
| 469 AddErrorToRootConsole(ASCIIToUTF16( | 479 AddMessageToRootConsole( |
| 470 "Icons are too large. Maximum total size for app icons is 128 KB.")); | 480 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
| 481 ASCIIToUTF16("Icons are too large. " |
| 482 "Maximum total size for app icons is 128 KB.")); |
| 471 return; | 483 return; |
| 472 } | 484 } |
| 473 actual_icon_size += current_size; | 485 actual_icon_size += current_size; |
| 474 } | 486 } |
| 475 | 487 |
| 476 Send(new ExtensionHostMsg_InstallApplication( | 488 Send(new ExtensionHostMsg_InstallApplication( |
| 477 routing_id(), *pending_app_info_)); | 489 routing_id(), *pending_app_info_)); |
| 478 pending_app_info_.reset(NULL); | 490 pending_app_info_.reset(NULL); |
| 479 } | 491 } |
| 480 | 492 |
| 481 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { | 493 void ExtensionHelper::AddMessageToRootConsole(ConsoleMessageLevel level, |
| 494 const string16& message) { |
| 482 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 495 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 496 WebConsoleMessage::Level target_level = WebConsoleMessage::LevelLog; |
| 497 switch (level) { |
| 498 case content::CONSOLE_MESSAGE_LEVEL_TIP: |
| 499 target_level = WebConsoleMessage::LevelTip; |
| 500 break; |
| 501 case content::CONSOLE_MESSAGE_LEVEL_LOG: |
| 502 target_level = WebConsoleMessage::LevelLog; |
| 503 break; |
| 504 case content::CONSOLE_MESSAGE_LEVEL_WARNING: |
| 505 target_level = WebConsoleMessage::LevelWarning; |
| 506 break; |
| 507 case content::CONSOLE_MESSAGE_LEVEL_ERROR: |
| 508 target_level = WebConsoleMessage::LevelError; |
| 509 break; |
| 510 } |
| 483 render_view()->GetWebView()->mainFrame()->addMessageToConsole( | 511 render_view()->GetWebView()->mainFrame()->addMessageToConsole( |
| 484 WebConsoleMessage(WebConsoleMessage::LevelError, message)); | 512 WebConsoleMessage(target_level, message)); |
| 485 } | 513 } |
| 486 } | 514 } |
| OLD | NEW |