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

Unified Diff: chrome/browser/automation/automation_provider_observers.cc

Issue 8416024: Re-land 107645 with static initializers removed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove static initializers Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/automation/automation_provider_observers.cc
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index f93c2f8a84eed86f6b09085bea598b2b037e1b37..ca64410240832c1179d6ad2d81780bab94606a25 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -1892,87 +1892,46 @@ void SavePackageNotificationObserver::Observe(
PageSnapshotTaker::PageSnapshotTaker(AutomationProvider* automation,
IPC::Message* reply_message,
- RenderViewHost* render_view,
+ TabContentsWrapper* tab_contents,
const FilePath& path)
: automation_(automation->AsWeakPtr()),
reply_message_(reply_message),
- render_view_(render_view),
- image_path_(path),
- received_width_(false) {}
+ tab_contents_(tab_contents),
+ image_path_(path) {
+ registrar_.Add(this, chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN,
+ content::NotificationService::AllSources());
+}
PageSnapshotTaker::~PageSnapshotTaker() {}
void PageSnapshotTaker::Start() {
- ExecuteScript(L"window.domAutomationController.send(document.width);");
-}
-
-void PageSnapshotTaker::OnDomOperationCompleted(const std::string& json) {
- int dimension;
- if (!base::StringToInt(json, &dimension)) {
- SendMessage(false, "could not parse received dimensions: " + json);
- } else if (!received_width_) {
- received_width_ = true;
- entire_page_size_.set_width(dimension);
-
- ExecuteScript(L"window.domAutomationController.send(document.height);");
- } else {
- entire_page_size_.set_height(dimension);
-
- ThumbnailGenerator* generator =
- g_browser_process->GetThumbnailGenerator();
- ThumbnailGenerator::ThumbnailReadyCallback callback =
- base::Bind(&PageSnapshotTaker::OnSnapshotTaken, base::Unretained(this));
- // Don't actually start the thumbnail generator, this leads to crashes on
- // Mac, crbug.com/62986. Instead, just hook the generator to the
- // RenderViewHost manually.
-
- generator->MonitorRenderer(render_view_, true);
- generator->AskForSnapshot(render_view_, false, callback,
- entire_page_size_, entire_page_size_);
+ StartObserving(tab_contents_->automation_tab_helper());
+ tab_contents_->automation_tab_helper()->SnapshotEntirePage();
+}
+
+void PageSnapshotTaker::OnSnapshotEntirePageACK(
+ bool success,
+ const std::vector<unsigned char>& png_data,
+ const std::string& error_msg) {
+ bool overall_success = success;
+ std::string overall_error_msg = error_msg;
+ if (success) {
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ int bytes_written = file_util::WriteFile(image_path_,
+ reinterpret_cast<const char*>(&png_data[0]), png_data.size());
+ overall_success = (bytes_written == static_cast<int>(png_data.size()));
+ if (!overall_success)
+ overall_error_msg = "could not write snapshot to disk";
}
+ SendMessage(overall_success, overall_error_msg);
}
-void PageSnapshotTaker::OnModalDialogShown() {
+void PageSnapshotTaker::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
SendMessage(false, "a modal dialog is active");
}
-void PageSnapshotTaker::OnSnapshotTaken(const SkBitmap& bitmap) {
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- std::vector<unsigned char> png_data;
- SkAutoLockPixels lock_input(bitmap);
- bool success = gfx::PNGCodec::Encode(
- reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
- gfx::PNGCodec::FORMAT_BGRA,
- gfx::Size(bitmap.width(), bitmap.height()),
- bitmap.rowBytes(),
- true, // discard_transparency
- std::vector<gfx::PNGCodec::Comment>(),
- &png_data);
- std::string error_msg;
- if (!success) {
- error_msg = "could not encode bitmap as PNG";
- } else {
- int bytes_written = file_util::WriteFile(image_path_,
- reinterpret_cast<char*>(&png_data[0]), png_data.size());
- success = bytes_written == static_cast<int>(png_data.size());
- if (!success)
- error_msg = "could not write snapshot to disk";
- }
- SendMessage(success, error_msg);
-}
-
-void PageSnapshotTaker::ExecuteScript(const std::wstring& javascript) {
- std::wstring set_automation_id;
- base::SStringPrintf(
- &set_automation_id,
- L"window.domAutomationController.setAutomationId(%d);",
- reply_message_->routing_id());
-
- render_view_->ExecuteJavascriptInWebFrame(string16(),
- WideToUTF16Hack(set_automation_id));
- render_view_->ExecuteJavascriptInWebFrame(string16(),
- WideToUTF16Hack(javascript));
-}
void PageSnapshotTaker::SendMessage(bool success,
const std::string& error_msg) {
« no previous file with comments | « chrome/browser/automation/automation_provider_observers.h ('k') | chrome/browser/automation/automation_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698