| OLD | NEW |
| 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 Loading... |
| 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 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 } | 1157 } |
| 1156 | 1158 |
| 1157 // static | 1159 // static |
| 1158 const int FindInPageNotificationObserver::kFindInPageRequestId = -1; | 1160 const int FindInPageNotificationObserver::kFindInPageRequestId = -1; |
| 1159 | 1161 |
| 1160 DomOperationObserver::DomOperationObserver() { | 1162 DomOperationObserver::DomOperationObserver() { |
| 1161 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 1163 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 1162 content::NotificationService::AllSources()); | 1164 content::NotificationService::AllSources()); |
| 1163 registrar_.Add(this, chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, | 1165 registrar_.Add(this, chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, |
| 1164 content::NotificationService::AllSources()); | 1166 content::NotificationService::AllSources()); |
| 1167 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED, |
| 1168 content::NotificationService::AllSources()); |
| 1165 } | 1169 } |
| 1166 | 1170 |
| 1167 DomOperationObserver::~DomOperationObserver() {} | 1171 DomOperationObserver::~DomOperationObserver() {} |
| 1168 | 1172 |
| 1169 void DomOperationObserver::Observe( | 1173 void DomOperationObserver::Observe( |
| 1170 int type, const content::NotificationSource& source, | 1174 int type, const content::NotificationSource& source, |
| 1171 const content::NotificationDetails& details) { | 1175 const content::NotificationDetails& details) { |
| 1172 if (type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE) { | 1176 if (type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE) { |
| 1173 content::Details<DomOperationNotificationDetails> dom_op_details(details); | 1177 content::Details<DomOperationNotificationDetails> dom_op_details(details); |
| 1174 OnDomOperationCompleted(dom_op_details->json()); | 1178 OnDomOperationCompleted(dom_op_details->json()); |
| 1175 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) { | 1179 } else if (type == chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN) { |
| 1176 OnModalDialogShown(); | 1180 OnModalDialogShown(); |
| 1181 } else if (type == chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED) { |
| 1182 TabContents* tab_contents = content::Source<TabContents>(source).ptr(); |
| 1183 if (tab_contents) { |
| 1184 TabContentsWrapper* wrapper = |
| 1185 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); |
| 1186 if (wrapper && |
| 1187 wrapper->content_settings()->IsContentBlocked( |
| 1188 CONTENT_SETTINGS_TYPE_JAVASCRIPT)) { |
| 1189 OnJavascriptBlocked(); |
| 1190 } |
| 1191 } |
| 1177 } | 1192 } |
| 1178 } | 1193 } |
| 1179 | 1194 |
| 1180 DomOperationMessageSender::DomOperationMessageSender( | 1195 DomOperationMessageSender::DomOperationMessageSender( |
| 1181 AutomationProvider* automation, | 1196 AutomationProvider* automation, |
| 1182 IPC::Message* reply_message, | 1197 IPC::Message* reply_message, |
| 1183 bool use_json_interface) | 1198 bool use_json_interface) |
| 1184 : automation_(automation->AsWeakPtr()), | 1199 : automation_(automation->AsWeakPtr()), |
| 1185 reply_message_(reply_message), | 1200 reply_message_(reply_message), |
| 1186 use_json_interface_(use_json_interface) { | 1201 use_json_interface_(use_json_interface) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1206 | 1221 |
| 1207 void DomOperationMessageSender::OnModalDialogShown() { | 1222 void DomOperationMessageSender::OnModalDialogShown() { |
| 1208 if (automation_ && use_json_interface_) { | 1223 if (automation_ && use_json_interface_) { |
| 1209 AutomationJSONReply(automation_, reply_message_.release()) | 1224 AutomationJSONReply(automation_, reply_message_.release()) |
| 1210 .SendError("Could not complete script execution because a modal " | 1225 .SendError("Could not complete script execution because a modal " |
| 1211 "dialog is active"); | 1226 "dialog is active"); |
| 1212 delete this; | 1227 delete this; |
| 1213 } | 1228 } |
| 1214 } | 1229 } |
| 1215 | 1230 |
| 1231 void DomOperationMessageSender::OnJavascriptBlocked() { |
| 1232 if (automation_ && use_json_interface_) { |
| 1233 AutomationJSONReply(automation_, reply_message_.release()) |
| 1234 .SendError("Javascript execution was blocked"); |
| 1235 delete this; |
| 1236 } |
| 1237 } |
| 1238 |
| 1216 DocumentPrintedNotificationObserver::DocumentPrintedNotificationObserver( | 1239 DocumentPrintedNotificationObserver::DocumentPrintedNotificationObserver( |
| 1217 AutomationProvider* automation, IPC::Message* reply_message) | 1240 AutomationProvider* automation, IPC::Message* reply_message) |
| 1218 : automation_(automation->AsWeakPtr()), | 1241 : automation_(automation->AsWeakPtr()), |
| 1219 success_(false), | 1242 success_(false), |
| 1220 reply_message_(reply_message) { | 1243 reply_message_(reply_message) { |
| 1221 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, | 1244 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, |
| 1222 content::NotificationService::AllSources()); | 1245 content::NotificationService::AllSources()); |
| 1223 } | 1246 } |
| 1224 | 1247 |
| 1225 DocumentPrintedNotificationObserver::~DocumentPrintedNotificationObserver() { | 1248 DocumentPrintedNotificationObserver::~DocumentPrintedNotificationObserver() { |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1929 generator->MonitorRenderer(render_view_, true); | 1952 generator->MonitorRenderer(render_view_, true); |
| 1930 generator->AskForSnapshot(render_view_, false, callback, | 1953 generator->AskForSnapshot(render_view_, false, callback, |
| 1931 entire_page_size_, entire_page_size_); | 1954 entire_page_size_, entire_page_size_); |
| 1932 } | 1955 } |
| 1933 } | 1956 } |
| 1934 | 1957 |
| 1935 void PageSnapshotTaker::OnModalDialogShown() { | 1958 void PageSnapshotTaker::OnModalDialogShown() { |
| 1936 SendMessage(false, "a modal dialog is active"); | 1959 SendMessage(false, "a modal dialog is active"); |
| 1937 } | 1960 } |
| 1938 | 1961 |
| 1962 void PageSnapshotTaker::OnJavascriptBlocked() { |
| 1963 SendMessage(false, "Javascript was blocked"); |
| 1964 } |
| 1965 |
| 1939 void PageSnapshotTaker::OnSnapshotTaken(const SkBitmap& bitmap) { | 1966 void PageSnapshotTaker::OnSnapshotTaken(const SkBitmap& bitmap) { |
| 1940 base::ThreadRestrictions::ScopedAllowIO allow_io; | 1967 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 1941 std::vector<unsigned char> png_data; | 1968 std::vector<unsigned char> png_data; |
| 1942 SkAutoLockPixels lock_input(bitmap); | 1969 SkAutoLockPixels lock_input(bitmap); |
| 1943 bool success = gfx::PNGCodec::Encode( | 1970 bool success = gfx::PNGCodec::Encode( |
| 1944 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), | 1971 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), |
| 1945 gfx::PNGCodec::FORMAT_BGRA, | 1972 gfx::PNGCodec::FORMAT_BGRA, |
| 1946 gfx::Size(bitmap.width(), bitmap.height()), | 1973 gfx::Size(bitmap.width(), bitmap.height()), |
| 1947 bitmap.rowBytes(), | 1974 bitmap.rowBytes(), |
| 1948 true, // discard_transparency | 1975 true, // discard_transparency |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2939 if (automation_) { | 2966 if (automation_) { |
| 2940 AutomationJSONReply(automation_, reply_message_.release()) | 2967 AutomationJSONReply(automation_, reply_message_.release()) |
| 2941 .SendSuccess(NULL); | 2968 .SendSuccess(NULL); |
| 2942 } | 2969 } |
| 2943 delete this; | 2970 delete this; |
| 2944 } | 2971 } |
| 2945 } else { | 2972 } else { |
| 2946 NOTREACHED(); | 2973 NOTREACHED(); |
| 2947 } | 2974 } |
| 2948 } | 2975 } |
| OLD | NEW |