Chromium Code Reviews| 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 d9a998e3f06758bf24d18926f531f9df4423d1b8..12f296d6c2de5bd597433da588d609f307333b2d 100644 |
| --- a/chrome/browser/automation/automation_provider_observers.cc |
| +++ b/chrome/browser/automation/automation_provider_observers.cc |
| @@ -1881,88 +1881,47 @@ 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, |
| + 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_); |
| - } |
| -} |
| - |
| -void PageSnapshotTaker::OnModalDialogShown() { |
| - 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 { |
| + 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<char*>(&png_data[0]), png_data.size()); |
| - success = bytes_written == static_cast<int>(png_data.size()); |
| + reinterpret_cast<const char*>(&png_data[0]), png_data.size()); |
| + overall_success = bytes_written == static_cast<int>(png_data.size()); |
|
Paweł Hajdan Jr.
2011/10/18 10:21:35
nit: Parentheses around bytes_written == ... pleas
kkania
2011/10/18 18:30:19
Done.
|
| if (!success) |
|
Paweł Hajdan Jr.
2011/10/18 10:21:35
nit: Did you mean overall_success here?
kkania
2011/10/18 18:30:19
Done.
|
| - error_msg = "could not write snapshot to disk"; |
| + overall_error_msg = "could not write snapshot to disk"; |
| } |
| - SendMessage(success, error_msg); |
| + SendMessage(overall_success, overall_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::Observe(int type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details) { |
| + SendMessage(false, "a modal dialog is active"); |
| } |
| + |
| void PageSnapshotTaker::SendMessage(bool success, |
| const std::string& error_msg) { |
| if (automation_) { |