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/callback.h" | 12 #include "base/callback.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 19 #include "base/utf_string_conversions.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "chrome/app/chrome_command_ids.h" | 21 #include "chrome/app/chrome_command_ids.h" |
21 #include "chrome/browser/automation/automation_provider.h" | 22 #include "chrome/browser/automation/automation_provider.h" |
22 #include "chrome/browser/automation/automation_provider_json.h" | 23 #include "chrome/browser/automation/automation_provider_json.h" |
23 #include "chrome/browser/bookmarks/bookmark_model.h" | 24 #include "chrome/browser/bookmarks/bookmark_model.h" |
24 #include "chrome/browser/browser_list.h" | 25 #include "chrome/browser/browser_list.h" |
25 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
26 #include "chrome/browser/dom_operation_notification_details.h" | 27 #include "chrome/browser/dom_operation_notification_details.h" |
27 #include "chrome/browser/dom_ui/most_visited_handler.h" | 28 #include "chrome/browser/dom_ui/most_visited_handler.h" |
28 #include "chrome/browser/dom_ui/new_tab_ui.h" | 29 #include "chrome/browser/dom_ui/new_tab_ui.h" |
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 IPC::Message* reply_message, | 1370 IPC::Message* reply_message, |
1370 RenderViewHost* render_view, | 1371 RenderViewHost* render_view, |
1371 const FilePath& path) | 1372 const FilePath& path) |
1372 : automation_(automation), | 1373 : automation_(automation), |
1373 reply_message_(reply_message), | 1374 reply_message_(reply_message), |
1374 render_view_(render_view), | 1375 render_view_(render_view), |
1375 image_path_(path), | 1376 image_path_(path), |
1376 received_width_(false) {} | 1377 received_width_(false) {} |
1377 | 1378 |
1378 void PageSnapshotTaker::Start() { | 1379 void PageSnapshotTaker::Start() { |
1379 ExecuteScript(L"window.domAutomationController.send(document.width);"); | 1380 ExecuteScript( |
| 1381 ASCIIToUTF16("window.domAutomationController.send(document.width);")); |
1380 } | 1382 } |
1381 | 1383 |
1382 void PageSnapshotTaker::OnDomOperationCompleted(const std::string& json) { | 1384 void PageSnapshotTaker::OnDomOperationCompleted(const std::string& json) { |
1383 int dimension; | 1385 int dimension; |
1384 if (!base::StringToInt(json, &dimension)) { | 1386 if (!base::StringToInt(json, &dimension)) { |
1385 LOG(ERROR) << "Could not parse received dimensions: " << json; | 1387 LOG(ERROR) << "Could not parse received dimensions: " << json; |
1386 SendMessage(false); | 1388 SendMessage(false); |
1387 } else if (!received_width_) { | 1389 } else if (!received_width_) { |
1388 received_width_ = true; | 1390 received_width_ = true; |
1389 entire_page_size_.set_width(dimension); | 1391 entire_page_size_.set_width(dimension); |
1390 | 1392 |
1391 ExecuteScript(L"window.domAutomationController.send(document.height);"); | 1393 ExecuteScript( |
| 1394 ASCIIToUTF16("window.domAutomationController.send(document.height);")); |
1392 } else { | 1395 } else { |
1393 entire_page_size_.set_height(dimension); | 1396 entire_page_size_.set_height(dimension); |
1394 | 1397 |
1395 ThumbnailGenerator* generator = | 1398 ThumbnailGenerator* generator = |
1396 g_browser_process->GetThumbnailGenerator(); | 1399 g_browser_process->GetThumbnailGenerator(); |
1397 ThumbnailGenerator::ThumbnailReadyCallback* callback = | 1400 ThumbnailGenerator::ThumbnailReadyCallback* callback = |
1398 NewCallback(this, &PageSnapshotTaker::OnSnapshotTaken); | 1401 NewCallback(this, &PageSnapshotTaker::OnSnapshotTaken); |
1399 // Don't actually start the thumbnail generator, this leads to crashes on | 1402 // Don't actually start the thumbnail generator, this leads to crashes on |
1400 // Mac, crbug.com/62986. Instead, just hook the generator to the | 1403 // Mac, crbug.com/62986. Instead, just hook the generator to the |
1401 // RenderViewHost manually. | 1404 // RenderViewHost manually. |
1402 | 1405 |
1403 generator->MonitorRenderer(render_view_, true); | 1406 generator->MonitorRenderer(render_view_, true); |
1404 generator->AskForSnapshot(render_view_, false, callback, | 1407 generator->AskForSnapshot(render_view_, false, callback, |
1405 entire_page_size_, entire_page_size_); | 1408 entire_page_size_, entire_page_size_); |
1406 } | 1409 } |
1407 } | 1410 } |
1408 | 1411 |
1409 void PageSnapshotTaker::OnSnapshotTaken(const SkBitmap& bitmap) { | 1412 void PageSnapshotTaker::OnSnapshotTaken(const SkBitmap& bitmap) { |
1410 base::ThreadRestrictions::ScopedAllowIO allow_io; | 1413 base::ThreadRestrictions::ScopedAllowIO allow_io; |
1411 std::vector<unsigned char> png_data; | 1414 std::vector<unsigned char> png_data; |
1412 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data); | 1415 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data); |
1413 int bytes_written = file_util::WriteFile(image_path_, | 1416 int bytes_written = file_util::WriteFile(image_path_, |
1414 reinterpret_cast<char*>(&png_data[0]), png_data.size()); | 1417 reinterpret_cast<char*>(&png_data[0]), png_data.size()); |
1415 SendMessage(bytes_written == static_cast<int>(png_data.size())); | 1418 SendMessage(bytes_written == static_cast<int>(png_data.size())); |
1416 } | 1419 } |
1417 | 1420 |
1418 void PageSnapshotTaker::ExecuteScript(const std::wstring& javascript) { | 1421 void PageSnapshotTaker::ExecuteScript(const string16& javascript) { |
1419 std::wstring set_automation_id; | 1422 std::string set_automation_id; |
1420 base::SStringPrintf( | 1423 base::SStringPrintf( |
1421 &set_automation_id, | 1424 &set_automation_id, |
1422 L"window.domAutomationController.setAutomationId(%d);", | 1425 "window.domAutomationController.setAutomationId(%d);", |
1423 reply_message_->routing_id()); | 1426 reply_message_->routing_id()); |
1424 | 1427 |
1425 render_view_->ExecuteJavascriptInWebFrame(L"", set_automation_id); | 1428 render_view_->ExecuteJavascriptInWebFrame(string16(), |
1426 render_view_->ExecuteJavascriptInWebFrame(L"", javascript); | 1429 UTF8ToUTF16(set_automation_id)); |
| 1430 render_view_->ExecuteJavascriptInWebFrame(string16(), |
| 1431 javascript); |
1427 } | 1432 } |
1428 | 1433 |
1429 void PageSnapshotTaker::SendMessage(bool success) { | 1434 void PageSnapshotTaker::SendMessage(bool success) { |
1430 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message_, | 1435 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message_, |
1431 success); | 1436 success); |
1432 automation_->Send(reply_message_); | 1437 automation_->Send(reply_message_); |
1433 delete this; | 1438 delete this; |
1434 } | 1439 } |
1435 | 1440 |
1436 NTPInfoObserver::NTPInfoObserver( | 1441 NTPInfoObserver::NTPInfoObserver( |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | 1727 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
1723 NewRunnableMethod( | 1728 NewRunnableMethod( |
1724 this, | 1729 this, |
1725 &WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread)); | 1730 &WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread)); |
1726 } | 1731 } |
1727 | 1732 |
1728 void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() { | 1733 void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() { |
1729 automation_->Send(reply_message_); | 1734 automation_->Send(reply_message_); |
1730 Release(); | 1735 Release(); |
1731 } | 1736 } |
OLD | NEW |