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

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

Issue 6312154: Remove wstring from RVH's run Javascript command.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 10 months 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/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
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("window.domAutomationController.send(document.width);");
1380 } 1381 }
1381 1382
1382 void PageSnapshotTaker::OnDomOperationCompleted(const std::string& json) { 1383 void PageSnapshotTaker::OnDomOperationCompleted(const std::string& json) {
1383 int dimension; 1384 int dimension;
1384 if (!base::StringToInt(json, &dimension)) { 1385 if (!base::StringToInt(json, &dimension)) {
1385 LOG(ERROR) << "Could not parse received dimensions: " << json; 1386 LOG(ERROR) << "Could not parse received dimensions: " << json;
1386 SendMessage(false); 1387 SendMessage(false);
1387 } else if (!received_width_) { 1388 } else if (!received_width_) {
1388 received_width_ = true; 1389 received_width_ = true;
1389 entire_page_size_.set_width(dimension); 1390 entire_page_size_.set_width(dimension);
1390 1391
1391 ExecuteScript(L"window.domAutomationController.send(document.height);"); 1392 ExecuteScript("window.domAutomationController.send(document.height);");
1392 } else { 1393 } else {
1393 entire_page_size_.set_height(dimension); 1394 entire_page_size_.set_height(dimension);
1394 1395
1395 ThumbnailGenerator* generator = 1396 ThumbnailGenerator* generator =
1396 g_browser_process->GetThumbnailGenerator(); 1397 g_browser_process->GetThumbnailGenerator();
1397 ThumbnailGenerator::ThumbnailReadyCallback* callback = 1398 ThumbnailGenerator::ThumbnailReadyCallback* callback =
1398 NewCallback(this, &PageSnapshotTaker::OnSnapshotTaken); 1399 NewCallback(this, &PageSnapshotTaker::OnSnapshotTaken);
1399 // Don't actually start the thumbnail generator, this leads to crashes on 1400 // Don't actually start the thumbnail generator, this leads to crashes on
1400 // Mac, crbug.com/62986. Instead, just hook the generator to the 1401 // Mac, crbug.com/62986. Instead, just hook the generator to the
1401 // RenderViewHost manually. 1402 // RenderViewHost manually.
1402 1403
1403 generator->MonitorRenderer(render_view_, true); 1404 generator->MonitorRenderer(render_view_, true);
1404 generator->AskForSnapshot(render_view_, false, callback, 1405 generator->AskForSnapshot(render_view_, false, callback,
1405 entire_page_size_, entire_page_size_); 1406 entire_page_size_, entire_page_size_);
1406 } 1407 }
1407 } 1408 }
1408 1409
1409 void PageSnapshotTaker::OnSnapshotTaken(const SkBitmap& bitmap) { 1410 void PageSnapshotTaker::OnSnapshotTaken(const SkBitmap& bitmap) {
1410 base::ThreadRestrictions::ScopedAllowIO allow_io; 1411 base::ThreadRestrictions::ScopedAllowIO allow_io;
1411 std::vector<unsigned char> png_data; 1412 std::vector<unsigned char> png_data;
1412 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data); 1413 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data);
1413 int bytes_written = file_util::WriteFile(image_path_, 1414 int bytes_written = file_util::WriteFile(image_path_,
1414 reinterpret_cast<char*>(&png_data[0]), png_data.size()); 1415 reinterpret_cast<char*>(&png_data[0]), png_data.size());
1415 SendMessage(bytes_written == static_cast<int>(png_data.size())); 1416 SendMessage(bytes_written == static_cast<int>(png_data.size()));
1416 } 1417 }
1417 1418
1418 void PageSnapshotTaker::ExecuteScript(const std::wstring& javascript) { 1419 void PageSnapshotTaker::ExecuteScript(const std::string& javascript) {
1419 std::wstring set_automation_id; 1420 std::string set_automation_id;
1420 base::SStringPrintf( 1421 base::SStringPrintf(
1421 &set_automation_id, 1422 &set_automation_id,
1422 L"window.domAutomationController.setAutomationId(%d);", 1423 "window.domAutomationController.setAutomationId(%d);",
1423 reply_message_->routing_id()); 1424 reply_message_->routing_id());
1424 1425
1425 render_view_->ExecuteJavascriptInWebFrame(L"", set_automation_id); 1426 render_view_->ExecuteJavascriptInWebFrame(string16(),
1426 render_view_->ExecuteJavascriptInWebFrame(L"", javascript); 1427 UTF8ToUTF16(set_automation_id));
1428 render_view_->ExecuteJavascriptInWebFrame(string16(),
1429 UTF8ToUTF16(javascript));
1427 } 1430 }
1428 1431
1429 void PageSnapshotTaker::SendMessage(bool success) { 1432 void PageSnapshotTaker::SendMessage(bool success) {
1430 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message_, 1433 AutomationMsg_CaptureEntirePageAsPNG::WriteReplyParams(reply_message_,
1431 success); 1434 success);
1432 automation_->Send(reply_message_); 1435 automation_->Send(reply_message_);
1433 delete this; 1436 delete this;
1434 } 1437 }
1435 1438
1436 NTPInfoObserver::NTPInfoObserver( 1439 NTPInfoObserver::NTPInfoObserver(
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 1725 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
1723 NewRunnableMethod( 1726 NewRunnableMethod(
1724 this, 1727 this,
1725 &WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread)); 1728 &WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread));
1726 } 1729 }
1727 1730
1728 void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() { 1731 void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() {
1729 automation_->Send(reply_message_); 1732 automation_->Send(reply_message_);
1730 Release(); 1733 Release();
1731 } 1734 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698