Commit 760679c3 authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

Move handling of Javascript console logs out of CRWWebController.

This CL moves the handling of Javascript console logs to an improved
architecture, but is a no-op in terms of functionality. This will allow
Javascript logs to be exposed in non-debug builds (instead of printing them to
the device console as is done currently).

Bug: 899851
Change-Id: I25eedc1f450df48acf66e4306f8846e0f761276f
Reviewed-on: https://chromium-review.googlesource.com/c/1338946
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611547}
parent 496b99e7
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#import "ios/chrome/browser/web/features.h" #import "ios/chrome/browser/web/features.h"
#import "ios/chrome/browser/web/font_size_tab_helper.h" #import "ios/chrome/browser/web/font_size_tab_helper.h"
#import "ios/chrome/browser/web/image_fetch_tab_helper.h" #import "ios/chrome/browser/web/image_fetch_tab_helper.h"
#import "ios/chrome/browser/web/java_script_console/java_script_console_tab_helper.h"
#import "ios/chrome/browser/web/load_timing_tab_helper.h" #import "ios/chrome/browser/web/load_timing_tab_helper.h"
#import "ios/chrome/browser/web/network_activity_indicator_tab_helper.h" #import "ios/chrome/browser/web/network_activity_indicator_tab_helper.h"
#import "ios/chrome/browser/web/page_placeholder_tab_helper.h" #import "ios/chrome/browser/web/page_placeholder_tab_helper.h"
...@@ -84,6 +85,7 @@ void AttachTabHelpers(web::WebState* web_state, bool for_prerender) { ...@@ -84,6 +85,7 @@ void AttachTabHelpers(web::WebState* web_state, bool for_prerender) {
BlockedPopupTabHelper::CreateForWebState(web_state); BlockedPopupTabHelper::CreateForWebState(web_state);
FindTabHelper::CreateForWebState(web_state); FindTabHelper::CreateForWebState(web_state);
StoreKitTabHelper::CreateForWebState(web_state); StoreKitTabHelper::CreateForWebState(web_state);
JavaScriptConsoleTabHelper::CreateForWebState(tab.webState);
if (base::FeatureList::IsEnabled(kITunesUrlsStoreKitHandling)) { if (base::FeatureList::IsEnabled(kITunesUrlsStoreKitHandling)) {
ITunesUrlsHandlerTabHelper::CreateForWebState(web_state); ITunesUrlsHandlerTabHelper::CreateForWebState(web_state);
} }
......
...@@ -143,6 +143,7 @@ js_compile_bundle("chrome_bundle_all_frames") { ...@@ -143,6 +143,7 @@ js_compile_bundle("chrome_bundle_all_frames") {
"//components/autofill/ios/form_util/resources/form_handlers.js", "//components/autofill/ios/form_util/resources/form_handlers.js",
"resources/accessibility.js", "resources/accessibility.js",
"resources/chrome_bundle_all_frames.js", "resources/chrome_bundle_all_frames.js",
"resources/console.js",
"resources/print.js", "resources/print.js",
] ]
} }
...@@ -185,6 +186,22 @@ js_compile_checked("image_fetch") { ...@@ -185,6 +186,22 @@ js_compile_checked("image_fetch") {
] ]
} }
source_set("java_script_console") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"java_script_console/java_script_console_message.cc",
"java_script_console/java_script_console_message.h",
"java_script_console/java_script_console_tab_helper.h",
"java_script_console/java_script_console_tab_helper.mm",
"java_script_console/java_script_console_tab_helper_delegate.h",
]
deps = [
"//base",
"//ios/web/public",
]
libs = [ "Foundation.framework" ]
}
source_set("web_internal") { source_set("web_internal") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
...@@ -233,6 +250,9 @@ source_set("web_internal") { ...@@ -233,6 +250,9 @@ source_set("web_internal") {
"//ui/gfx", "//ui/gfx",
"//url", "//url",
] ]
public_deps = [
":java_script_console",
]
libs = [ libs = [
"UIKit.framework", "UIKit.framework",
"Foundation.framework", "Foundation.framework",
...@@ -265,6 +285,7 @@ source_set("unit_tests_internal") { ...@@ -265,6 +285,7 @@ source_set("unit_tests_internal") {
sources = [ sources = [
"blocked_popup_tab_helper_unittest.mm", "blocked_popup_tab_helper_unittest.mm",
"chrome_web_client_unittest.mm", "chrome_web_client_unittest.mm",
"java_script_console/java_script_console_tab_helper_unittest.mm",
] ]
deps = [ deps = [
":test_support", ":test_support",
...@@ -282,6 +303,7 @@ source_set("unit_tests_internal") { ...@@ -282,6 +303,7 @@ source_set("unit_tests_internal") {
"//ios/chrome/browser/passwords", "//ios/chrome/browser/passwords",
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/web", "//ios/chrome/browser/web",
"//ios/chrome/test/fakes",
"//ios/web", "//ios/web",
"//ios/web/public/test", "//ios/web/public/test",
"//ios/web/public/test/fakes", "//ios/web/public/test/fakes",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/web/java_script_console/java_script_console_message.h"
JavaScriptConsoleMessage::JavaScriptConsoleMessage() {}
JavaScriptConsoleMessage::JavaScriptConsoleMessage(
const JavaScriptConsoleMessage& other)
: origin(other.origin),
level(other.level),
message(base::Value::ToUniquePtrValue(other.message->Clone())) {}
JavaScriptConsoleMessage& JavaScriptConsoleMessage::operator=(
JavaScriptConsoleMessage other) {
origin = other.origin;
level = other.level;
message = std::move(other.message);
return *this;
}
JavaScriptConsoleMessage::~JavaScriptConsoleMessage() {}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_WEB_JAVA_SCRIPT_CONSOLE_JAVA_SCRIPT_CONSOLE_MESSAGE_H_
#define IOS_CHROME_BROWSER_WEB_JAVA_SCRIPT_CONSOLE_JAVA_SCRIPT_CONSOLE_MESSAGE_H_
#include "base/macros.h"
#include "base/values.h"
#include "url/gurl.h"
// Wraps information from a received console message.
struct JavaScriptConsoleMessage {
public:
JavaScriptConsoleMessage();
JavaScriptConsoleMessage(const JavaScriptConsoleMessage& other);
JavaScriptConsoleMessage& operator=(JavaScriptConsoleMessage other);
~JavaScriptConsoleMessage();
// The origin of the frame which sent the message.
GURL origin;
// The log level associated with the message. (From console.js, i.e. "log",
// "debug", "info", "warn", "error")
std::string level;
// The message contents.
std::unique_ptr<base::Value> message;
DISALLOW_ASSIGN(JavaScriptConsoleMessage);
};
#endif // IOS_CHROME_BROWSER_WEB_JAVA_SCRIPT_CONSOLE_JAVA_SCRIPT_CONSOLE_MESSAGE_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_WEB_JAVA_SCRIPT_CONSOLE_JAVA_SCRIPT_CONSOLE_TAB_HELPER_H_
#define IOS_CHROME_BROWSER_WEB_JAVA_SCRIPT_CONSOLE_JAVA_SCRIPT_CONSOLE_TAB_HELPER_H_
#include "base/values.h"
#include "ios/chrome/browser/web/java_script_console/java_script_console_tab_helper_delegate.h"
#include "ios/web/public/web_state/web_state_observer.h"
#import "ios/web/public/web_state/web_state_user_data.h"
namespace web {
class WebFrame;
class WebState;
} // namespace web
// Receives JavaScript console log messages and forwards them to the delegate.
class JavaScriptConsoleTabHelper
: public web::WebStateUserData<JavaScriptConsoleTabHelper>,
public web::WebStateObserver {
public:
~JavaScriptConsoleTabHelper() override;
// The delegate associated with the receiver. The delegate will be notified of
// new JavaScript messages.
void SetDelegate(JavaScriptConsoleTabHelperDelegate* delegate);
private:
// Handles the received JavaScript messages.
bool OnJavaScriptConsoleMessage(const base::DictionaryValue& message,
const GURL& page_url,
bool has_user_gesture,
bool main_frame,
web::WebFrame* sender_frame);
// WebStateObserver overrides.
void WebStateDestroyed(web::WebState* web_state) override;
explicit JavaScriptConsoleTabHelper(web::WebState* web_state);
friend class web::WebStateUserData<JavaScriptConsoleTabHelper>;
// The delegate associated with the receiver.
JavaScriptConsoleTabHelperDelegate* delegate_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(JavaScriptConsoleTabHelper);
};
#endif // IOS_CHROME_BROWSER_WEB_JAVA_SCRIPT_CONSOLE_JAVA_SCRIPT_CONSOLE_TAB_HELPER_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/web/java_script_console/java_script_console_tab_helper.h"
#import <Foundation/Foundation.h>
#include "base/values.h"
#include "ios/chrome/browser/web/java_script_console/java_script_console_message.h"
#include "ios/web/public/web_state/web_frame.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Name of message to which javascript console messages are sent.
static const char* kCommandPrefix = "console";
// Standard User Defaults key for "Log JS" debug setting.
NSString* const kLogJavaScript = @"LogJavascript";
}
JavaScriptConsoleTabHelper::JavaScriptConsoleTabHelper(
web::WebState* web_state) {
web_state->AddObserver(this);
web_state->AddScriptCommandCallback(
base::BindRepeating(
&JavaScriptConsoleTabHelper::OnJavaScriptConsoleMessage,
base::Unretained(this)),
kCommandPrefix);
}
bool JavaScriptConsoleTabHelper::OnJavaScriptConsoleMessage(
const base::DictionaryValue& message,
const GURL& page_url,
bool has_user_gesture,
bool main_frame,
web::WebFrame* sender_frame) {
const base::Value* log_message = message.FindKey("message");
const base::Value* log_level_value = message.FindKey("method");
const base::Value* origin_value = message.FindKey("origin");
if (!log_message || !log_level_value || !log_level_value->is_string() ||
!origin_value || !origin_value->is_string()) {
return false;
}
std::string log_level = log_level_value->GetString();
std::string origin = origin_value->GetString();
if ([[NSUserDefaults standardUserDefaults] boolForKey:kLogJavaScript]) {
DVLOG(0) << origin << " [" << log_level << "] " << log_message;
}
if (!delegate_) {
return true;
}
JavaScriptConsoleMessage frame_message;
frame_message.level = log_level;
frame_message.origin = GURL(origin);
frame_message.message = base::Value::ToUniquePtrValue(log_message->Clone());
delegate_->DidReceiveConsoleMessage(frame_message);
return true;
}
void JavaScriptConsoleTabHelper::WebStateDestroyed(web::WebState* web_state) {
web_state->RemoveScriptCommandCallback(kCommandPrefix);
web_state->RemoveObserver(this);
}
void JavaScriptConsoleTabHelper::SetDelegate(
JavaScriptConsoleTabHelperDelegate* delegate) {
delegate_ = delegate;
}
JavaScriptConsoleTabHelper::~JavaScriptConsoleTabHelper() = default;
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_WEB_JAVA_SCRIPT_CONSOLE_JAVA_SCRIPT_CONSOLE_TAB_HELPER_DELEGATE_H_
#define IOS_CHROME_BROWSER_WEB_JAVA_SCRIPT_CONSOLE_JAVA_SCRIPT_CONSOLE_TAB_HELPER_DELEGATE_H_
struct JavaScriptConsoleMessage;
class JavaScriptConsoleTabHelperDelegate {
public:
// Called when a JavaScript message has been logged.
virtual void DidReceiveConsoleMessage(
const JavaScriptConsoleMessage& message) = 0;
virtual ~JavaScriptConsoleTabHelperDelegate() {}
};
#endif // IOS_CHROME_BROWSER_WEB_JAVA_SCRIPT_CONSOLE_JAVA_SCRIPT_CONSOLE_TAB_HELPER_DELEGATE_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/web/java_script_console/java_script_console_tab_helper.h"
#include "base/values.h"
#import "ios/chrome/browser/web/chrome_web_client.h"
#import "ios/chrome/browser/web/chrome_web_test.h"
#include "ios/chrome/browser/web/java_script_console/java_script_console_message.h"
#include "ios/chrome/browser/web/java_script_console/java_script_console_tab_helper_delegate.h"
#include "ios/chrome/test/fakes/fake_java_script_console_tab_helper_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Test fixture to test JavaScriptConsoleTabHelper.
class JavaScriptConsoleTabHelperTest : public ChromeWebTest {
protected:
JavaScriptConsoleTabHelperTest()
: ChromeWebTest(std::make_unique<ChromeWebClient>()) {}
void SetUp() override {
ChromeWebTest::SetUp();
JavaScriptConsoleTabHelper::CreateForWebState(web_state());
}
// Loads the given HTML and initializes the JS scripts.
void LoadHtml(NSString* html, GURL url) {
ChromeWebTest::LoadHtml(html, url);
ExecuteJavaScript(
GetWebClient()->GetDocumentStartScriptForAllFrames(GetBrowserState()));
}
// Returns the JavaScriptConsoleTabHelper associated with |web_state()|.
JavaScriptConsoleTabHelper* tab_helper() {
return JavaScriptConsoleTabHelper::FromWebState(web_state());
}
};
// Tests that a message can be logged without a
// JavaScriptConsoleTabHelperDelegate set.
TEST_F(JavaScriptConsoleTabHelperTest, LogMessageWithoutDelegate) {
LoadHtml(@"<p></p>", GURL("http://chromium.test"));
ASSERT_TRUE(tab_helper());
// No need to verify state, but logging a message should not crash the
// JavaScriptConsoleTabHelper when it has no delegate.
ExecuteJavaScript(@"console.log('Log message');");
};
// Tests that a JavaScript console message is logged correctly.
TEST_F(JavaScriptConsoleTabHelperTest, LogMessage) {
GURL url = GURL("http://chromium.test");
LoadHtml(@"<p></p>", url);
auto delegate = std::make_unique<FakeJavaScriptConsoleTabHelperDelegate>();
ASSERT_TRUE(tab_helper());
tab_helper()->SetDelegate(delegate.get());
ASSERT_FALSE(delegate->GetLastLoggedMessage());
ExecuteJavaScript(@"console.log('Log message');");
const JavaScriptConsoleMessage* last_logged_message =
delegate->GetLastLoggedMessage();
ASSERT_TRUE(last_logged_message);
EXPECT_EQ("log", last_logged_message->level);
EXPECT_EQ(url, last_logged_message->origin);
EXPECT_EQ("Log message", last_logged_message->message->GetString());
};
...@@ -7,6 +7,7 @@ goog.provide('__crWeb.chromeBundleAllFrames'); ...@@ -7,6 +7,7 @@ goog.provide('__crWeb.chromeBundleAllFrames');
goog.require('__crWeb.accessibility'); goog.require('__crWeb.accessibility');
goog.require('__crWeb.autofill'); goog.require('__crWeb.autofill');
goog.require('__crWeb.console');
goog.require('__crWeb.fill'); goog.require('__crWeb.fill');
goog.require('__crWeb.form'); goog.require('__crWeb.form');
goog.require('__crWeb.formHandlers'); goog.require('__crWeb.formHandlers');
......
...@@ -23,7 +23,7 @@ function sendConsoleMessage(method, originalArgs) { ...@@ -23,7 +23,7 @@ function sendConsoleMessage(method, originalArgs) {
} catch (err) { } catch (err) {
} }
__gCrWeb.message.invokeOnHost({ __gCrWeb.message.invokeOnHost({
'command': 'console', 'command': 'console.msg',
'method': method, 'method': method,
'message': message, 'message': message,
'origin': document.location.origin 'origin': document.location.origin
......
...@@ -15,6 +15,8 @@ source_set("fakes") { ...@@ -15,6 +15,8 @@ source_set("fakes") {
"fake_download_manager_consumer.mm", "fake_download_manager_consumer.mm",
"fake_download_manager_tab_helper_delegate.h", "fake_download_manager_tab_helper_delegate.h",
"fake_download_manager_tab_helper_delegate.mm", "fake_download_manager_tab_helper_delegate.mm",
"fake_java_script_console_tab_helper_delegate.cc",
"fake_java_script_console_tab_helper_delegate.h",
"fake_pass_kit_tab_helper_delegate.h", "fake_pass_kit_tab_helper_delegate.h",
"fake_pass_kit_tab_helper_delegate.mm", "fake_pass_kit_tab_helper_delegate.mm",
"fake_store_kit_launcher.h", "fake_store_kit_launcher.h",
...@@ -33,6 +35,7 @@ source_set("fakes") { ...@@ -33,6 +35,7 @@ source_set("fakes") {
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/download", "//ios/chrome/browser/ui/download",
"//ios/chrome/browser/ui/presenters", "//ios/chrome/browser/ui/presenters",
"//ios/chrome/browser/web:web_internal",
"//ios/web/public", "//ios/web/public",
"//ios/web/public/download", "//ios/web/public/download",
] ]
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/test/fakes/fake_java_script_console_tab_helper_delegate.h"
FakeJavaScriptConsoleTabHelperDelegate::
FakeJavaScriptConsoleTabHelperDelegate() {}
FakeJavaScriptConsoleTabHelperDelegate::
~FakeJavaScriptConsoleTabHelperDelegate() = default;
void FakeJavaScriptConsoleTabHelperDelegate::DidReceiveConsoleMessage(
const JavaScriptConsoleMessage& message) {
last_received_message_ = std::make_unique<JavaScriptConsoleMessage>(message);
}
const JavaScriptConsoleMessage*
FakeJavaScriptConsoleTabHelperDelegate::GetLastLoggedMessage() const {
return last_received_message_.get();
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_TEST_FAKES_FAKE_JAVA_SCRIPT_CONSOLE_TAB_HELPER_DELEGATE_H_
#define IOS_CHROME_TEST_FAKES_FAKE_JAVA_SCRIPT_CONSOLE_TAB_HELPER_DELEGATE_H_
#include <memory>
#include "ios/chrome/browser/web/java_script_console/java_script_console_message.h"
#include "ios/chrome/browser/web/java_script_console/java_script_console_tab_helper_delegate.h"
// A JavaScriptConsoleTabHelperDelegate class which stores the last received
// message from |DidReceiveConsoleMessage|.
class FakeJavaScriptConsoleTabHelperDelegate
: public JavaScriptConsoleTabHelperDelegate {
public:
FakeJavaScriptConsoleTabHelperDelegate();
~FakeJavaScriptConsoleTabHelperDelegate() override;
void DidReceiveConsoleMessage(
const JavaScriptConsoleMessage& message) override;
// Returns the last messaged logged.
const JavaScriptConsoleMessage* GetLastLoggedMessage() const;
private:
// The last received message.
std::unique_ptr<JavaScriptConsoleMessage> last_received_message_;
};
#endif // IOS_CHROME_TEST_FAKES_FAKE_JAVA_SCRIPT_CONSOLE_TAB_HELPER_DELEGATE_H_
...@@ -612,7 +612,6 @@ js_compile_bundle("main_frame_web_bundle") { ...@@ -612,7 +612,6 @@ js_compile_bundle("main_frame_web_bundle") {
closure_entry_point = "__crWeb.mainFrameWebBundle" closure_entry_point = "__crWeb.mainFrameWebBundle"
sources = [ sources = [
"web_state/js/resources/console.js",
"web_state/js/resources/error.js", "web_state/js/resources/error.js",
"web_state/js/resources/legacy.js", "web_state/js/resources/legacy.js",
"web_state/js/resources/main_frame_context_menu.js", "web_state/js/resources/main_frame_context_menu.js",
......
...@@ -7,7 +7,6 @@ goog.provide('__crWeb.mainFrameWebBundle'); ...@@ -7,7 +7,6 @@ goog.provide('__crWeb.mainFrameWebBundle');
// Requires __crWeb.form provided by __crWeb.allFramesWebBundle. // Requires __crWeb.form provided by __crWeb.allFramesWebBundle.
goog.require('__crWeb.console');
goog.require('__crWeb.error'); goog.require('__crWeb.error');
goog.require('__crWeb.legacy'); goog.require('__crWeb.legacy');
goog.require('__crWeb.mainFrameContextMenu'); goog.require('__crWeb.mainFrameContextMenu');
......
...@@ -158,9 +158,6 @@ NSString* const kFrameBecameAvailableMessageName = @"FrameBecameAvailable"; ...@@ -158,9 +158,6 @@ NSString* const kFrameBecameAvailableMessageName = @"FrameBecameAvailable";
// Message command sent when a frame is unloading. // Message command sent when a frame is unloading.
NSString* const kFrameBecameUnavailableMessageName = @"FrameBecameUnavailable"; NSString* const kFrameBecameUnavailableMessageName = @"FrameBecameUnavailable";
// Standard User Defaults key for "Log JS" debug setting.
NSString* const kLogJavaScript = @"LogJavascript";
// Values for the histogram that counts slow/fast back/forward navigations. // Values for the histogram that counts slow/fast back/forward navigations.
enum class BackForwardNavigationType { enum class BackForwardNavigationType {
// Fast back navigation through WKWebView back-forward list. // Fast back navigation through WKWebView back-forward list.
...@@ -832,9 +829,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -832,9 +829,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
// Handles 'chrome.send' message. // Handles 'chrome.send' message.
- (BOOL)handleChromeSendMessage:(base::DictionaryValue*)message - (BOOL)handleChromeSendMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context; context:(NSDictionary*)context;
// Handles 'console' message.
- (BOOL)handleConsoleMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context;
// Handles 'document.favicons' message. // Handles 'document.favicons' message.
- (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context; context:(NSDictionary*)context;
...@@ -2439,7 +2433,6 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -2439,7 +2433,6 @@ registerLoadRequestForURL:(const GURL&)requestURL
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
handlers = new std::map<std::string, SEL>(); handlers = new std::map<std::string, SEL>();
(*handlers)["chrome.send"] = @selector(handleChromeSendMessage:context:); (*handlers)["chrome.send"] = @selector(handleChromeSendMessage:context:);
(*handlers)["console"] = @selector(handleConsoleMessage:context:);
(*handlers)["document.favicons"] = (*handlers)["document.favicons"] =
@selector(handleDocumentFaviconsMessage:context:); @selector(handleDocumentFaviconsMessage:context:);
(*handlers)["window.error"] = @selector(handleWindowErrorMessage:context:); (*handlers)["window.error"] = @selector(handleWindowErrorMessage:context:);
...@@ -2650,35 +2643,6 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -2650,35 +2643,6 @@ registerLoadRequestForURL:(const GURL&)requestURL
return NO; return NO;
} }
- (BOOL)handleConsoleMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context {
if (![context[kIsMainFrame] boolValue])
return NO;
// Do not log if JS logging is off.
if (![[NSUserDefaults standardUserDefaults] boolForKey:kLogJavaScript]) {
return YES;
}
std::string method;
if (!message->GetString("method", &method)) {
DLOG(WARNING) << "JS message parameter not found: method";
return NO;
}
std::string consoleMessage;
if (!message->GetString("message", &consoleMessage)) {
DLOG(WARNING) << "JS message parameter not found: message";
return NO;
}
std::string origin;
if (!message->GetString("origin", &origin)) {
DLOG(WARNING) << "JS message parameter not found: origin";
return NO;
}
DVLOG(0) << origin << " [" << method << "] " << consoleMessage;
return YES;
}
- (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message
context:(NSDictionary*)context { context:(NSDictionary*)context {
if (![context[kIsMainFrame] boolValue]) if (![context[kIsMainFrame] boolValue])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment