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

Side by Side Diff: chrome/browser/automation/automation_provider_observers.cc

Issue 8395044: Disable the Developer Tools when Javascript is disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit_tests, added some more tests Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/automation/automation_provider_observers.h" 5 #include "chrome/browser/automation/automation_provider_observers.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/json/json_value_serializer.h" 16 #include "base/json/json_value_serializer.h"
17 #include "base/json/json_writer.h" 17 #include "base/json/json_writer.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/string_number_conversions.h" 19 #include "base/string_number_conversions.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/stringprintf.h" 21 #include "base/stringprintf.h"
22 #include "base/threading/thread_restrictions.h" 22 #include "base/threading/thread_restrictions.h"
23 #include "base/utf_string_conversions.h" 23 #include "base/utf_string_conversions.h"
24 #include "base/values.h" 24 #include "base/values.h"
25 #include "chrome/app/chrome_command_ids.h" 25 #include "chrome/app/chrome_command_ids.h"
26 #include "chrome/browser/automation/automation_provider.h" 26 #include "chrome/browser/automation/automation_provider.h"
27 #include "chrome/browser/automation/automation_provider_json.h" 27 #include "chrome/browser/automation/automation_provider_json.h"
28 #include "chrome/browser/bookmarks/bookmark_model.h" 28 #include "chrome/browser/bookmarks/bookmark_model.h"
29 #include "chrome/browser/browser_process.h" 29 #include "chrome/browser/browser_process.h"
30 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
30 #include "chrome/browser/dom_operation_notification_details.h" 31 #include "chrome/browser/dom_operation_notification_details.h"
31 #include "chrome/browser/extensions/crx_installer.h" 32 #include "chrome/browser/extensions/crx_installer.h"
32 #include "chrome/browser/extensions/extension_host.h" 33 #include "chrome/browser/extensions/extension_host.h"
33 #include "chrome/browser/extensions/extension_process_manager.h" 34 #include "chrome/browser/extensions/extension_process_manager.h"
34 #include "chrome/browser/extensions/extension_service.h" 35 #include "chrome/browser/extensions/extension_service.h"
35 #include "chrome/browser/extensions/extension_tab_util.h" 36 #include "chrome/browser/extensions/extension_tab_util.h"
36 #include "chrome/browser/extensions/extension_updater.h" 37 #include "chrome/browser/extensions/extension_updater.h"
37 #include "chrome/browser/history/history_types.h" 38 #include "chrome/browser/history/history_types.h"
38 #include "chrome/browser/history/top_sites.h" 39 #include "chrome/browser/history/top_sites.h"
39 #include "chrome/browser/infobars/infobar_tab_helper.h" 40 #include "chrome/browser/infobars/infobar_tab_helper.h"
(...skipping 22 matching lines...) Expand all
62 #include "chrome/browser/ui/browser_window.h" 63 #include "chrome/browser/ui/browser_window.h"
63 #include "chrome/browser/ui/find_bar/find_notification_details.h" 64 #include "chrome/browser/ui/find_bar/find_notification_details.h"
64 #include "chrome/browser/ui/login/login_prompt.h" 65 #include "chrome/browser/ui/login/login_prompt.h"
65 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 66 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
66 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 67 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
67 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h" 68 #include "chrome/browser/ui/webui/ntp/most_visited_handler.h"
68 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 69 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
69 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h" 70 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h"
70 #include "chrome/common/automation_messages.h" 71 #include "chrome/common/automation_messages.h"
71 #include "chrome/common/chrome_notification_types.h" 72 #include "chrome/common/chrome_notification_types.h"
73 #include "chrome/common/content_settings_types.h"
72 #include "chrome/common/extensions/extension.h" 74 #include "chrome/common/extensions/extension.h"
73 #include "content/browser/download/save_package.h" 75 #include "content/browser/download/save_package.h"
74 #include "content/browser/renderer_host/render_process_host.h" 76 #include "content/browser/renderer_host/render_process_host.h"
75 #include "content/browser/renderer_host/render_view_host.h" 77 #include "content/browser/renderer_host/render_view_host.h"
76 #include "content/browser/tab_contents/navigation_controller.h" 78 #include "content/browser/tab_contents/navigation_controller.h"
77 #include "content/browser/tab_contents/tab_contents.h" 79 #include "content/browser/tab_contents/tab_contents.h"
78 #include "content/common/child_process_info.h" 80 #include "content/common/child_process_info.h"
79 #include "content/public/browser/notification_service.h" 81 #include "content/public/browser/notification_service.h"
80 #include "googleurl/src/gurl.h" 82 #include "googleurl/src/gurl.h"
81 #include "third_party/skia/include/core/SkBitmap.h" 83 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 } 1159 }
1158 1160
1159 // static 1161 // static
1160 const int FindInPageNotificationObserver::kFindInPageRequestId = -1; 1162 const int FindInPageNotificationObserver::kFindInPageRequestId = -1;
1161 1163
1162 DomOperationObserver::DomOperationObserver() { 1164 DomOperationObserver::DomOperationObserver() {
1163 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, 1165 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE,
1164 content::NotificationService::AllSources()); 1166 content::NotificationService::AllSources());
1165 registrar_.Add(this, chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, 1167 registrar_.Add(this, chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN,
1166 content::NotificationService::AllSources()); 1168 content::NotificationService::AllSources());
1169 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED,
1170 content::NotificationService::AllSources());
1167 } 1171 }
1168 1172
1169 DomOperationObserver::~DomOperationObserver() {} 1173 DomOperationObserver::~DomOperationObserver() {}
1170 1174
1171 void DomOperationObserver::Observe( 1175 void DomOperationObserver::Observe(
1172 int type, const content::NotificationSource& source, 1176 int type, const content::NotificationSource& source,
1173 const content::NotificationDetails& details) { 1177 const content::NotificationDetails& details) {
1174 if (type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE) { 1178 if (type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE) {
1175 content::Details<DomOperationNotificationDetails> dom_op_details(details); 1179 content::Details<DomOperationNotificationDetails> dom_op_details(details);
1176 OnDomOperationCompleted(dom_op_details->json()); 1180 OnDomOperationCompleted(dom_op_details->json());
1177 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) { 1181 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) {
1178 OnModalDialogShown(); 1182 OnModalDialogShown();
1183 } else if (type == chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED) {
1184 TabContents* tab_contents = content::Source<TabContents>(source).ptr();
1185 if (tab_contents) {
1186 TabContentsWrapper* wrapper =
1187 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
1188 if (wrapper &&
1189 wrapper->content_settings()->IsContentBlocked(
1190 CONTENT_SETTINGS_TYPE_JAVASCRIPT)) {
1191 OnJavascriptBlocked();
1192 }
1193 }
1179 } 1194 }
1180 } 1195 }
1181 1196
1182 DomOperationMessageSender::DomOperationMessageSender( 1197 DomOperationMessageSender::DomOperationMessageSender(
1183 AutomationProvider* automation, 1198 AutomationProvider* automation,
1184 IPC::Message* reply_message, 1199 IPC::Message* reply_message,
1185 bool use_json_interface) 1200 bool use_json_interface)
1186 : automation_(automation->AsWeakPtr()), 1201 : automation_(automation->AsWeakPtr()),
1187 reply_message_(reply_message), 1202 reply_message_(reply_message),
1188 use_json_interface_(use_json_interface) { 1203 use_json_interface_(use_json_interface) {
(...skipping 19 matching lines...) Expand all
1208 1223
1209 void DomOperationMessageSender::OnModalDialogShown() { 1224 void DomOperationMessageSender::OnModalDialogShown() {
1210 if (automation_ && use_json_interface_) { 1225 if (automation_ && use_json_interface_) {
1211 AutomationJSONReply(automation_, reply_message_.release()) 1226 AutomationJSONReply(automation_, reply_message_.release())
1212 .SendError("Could not complete script execution because a modal " 1227 .SendError("Could not complete script execution because a modal "
1213 "dialog is active"); 1228 "dialog is active");
1214 delete this; 1229 delete this;
1215 } 1230 }
1216 } 1231 }
1217 1232
1233 void DomOperationMessageSender::OnJavascriptBlocked() {
1234 if (automation_ && use_json_interface_) {
1235 AutomationJSONReply(automation_, reply_message_.release())
1236 .SendError("Javascript execution was blocked");
1237 delete this;
1238 }
1239 }
1240
1218 DocumentPrintedNotificationObserver::DocumentPrintedNotificationObserver( 1241 DocumentPrintedNotificationObserver::DocumentPrintedNotificationObserver(
1219 AutomationProvider* automation, IPC::Message* reply_message) 1242 AutomationProvider* automation, IPC::Message* reply_message)
1220 : automation_(automation->AsWeakPtr()), 1243 : automation_(automation->AsWeakPtr()),
1221 success_(false), 1244 success_(false),
1222 reply_message_(reply_message) { 1245 reply_message_(reply_message) {
1223 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, 1246 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT,
1224 content::NotificationService::AllSources()); 1247 content::NotificationService::AllSources());
1225 } 1248 }
1226 1249
1227 DocumentPrintedNotificationObserver::~DocumentPrintedNotificationObserver() { 1250 DocumentPrintedNotificationObserver::~DocumentPrintedNotificationObserver() {
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 } 1950 }
1928 SendMessage(overall_success, overall_error_msg); 1951 SendMessage(overall_success, overall_error_msg);
1929 } 1952 }
1930 1953
1931 void PageSnapshotTaker::Observe(int type, 1954 void PageSnapshotTaker::Observe(int type,
1932 const content::NotificationSource& source, 1955 const content::NotificationSource& source,
1933 const content::NotificationDetails& details) { 1956 const content::NotificationDetails& details) {
1934 SendMessage(false, "a modal dialog is active"); 1957 SendMessage(false, "a modal dialog is active");
1935 } 1958 }
1936 1959
1937
1938 void PageSnapshotTaker::SendMessage(bool success, 1960 void PageSnapshotTaker::SendMessage(bool success,
1939 const std::string& error_msg) { 1961 const std::string& error_msg) {
1940 if (automation_) { 1962 if (automation_) {
1941 if (success) { 1963 if (success) {
1942 AutomationJSONReply(automation_, reply_message_.release()) 1964 AutomationJSONReply(automation_, reply_message_.release())
1943 .SendSuccess(NULL); 1965 .SendSuccess(NULL);
1944 } else { 1966 } else {
1945 AutomationJSONReply(automation_, reply_message_.release()) 1967 AutomationJSONReply(automation_, reply_message_.release())
1946 .SendError("Failed to take snapshot of page: " + error_msg); 1968 .SendError("Failed to take snapshot of page: " + error_msg);
1947 } 1969 }
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
2900 if (automation_) { 2922 if (automation_) {
2901 AutomationJSONReply(automation_, reply_message_.release()) 2923 AutomationJSONReply(automation_, reply_message_.release())
2902 .SendSuccess(NULL); 2924 .SendSuccess(NULL);
2903 } 2925 }
2904 delete this; 2926 delete this;
2905 } 2927 }
2906 } else { 2928 } else {
2907 NOTREACHED(); 2929 NOTREACHED();
2908 } 2930 }
2909 } 2931 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698