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

Unified Diff: ios/chrome/browser/web/print_observer.mm

Issue 2580333003: Upstream Chrome on iOS source code [10/11]. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « ios/chrome/browser/web/print_observer.h ('k') | ios/chrome/browser/web/progress_indicator_egtest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/web/print_observer.mm
diff --git a/ios/chrome/browser/web/print_observer.mm b/ios/chrome/browser/web/print_observer.mm
new file mode 100644
index 0000000000000000000000000000000000000000..0be1238e96cd98140b6abfdb4afd84e16311e8dd
--- /dev/null
+++ b/ios/chrome/browser/web/print_observer.mm
@@ -0,0 +1,49 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/chrome/browser/web/print_observer.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#import "base/mac/scoped_nsobject.h"
+#include "base/values.h"
+#import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
+#import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
+#include "ios/chrome/browser/ui/commands/ios_command_ids.h"
+#import "ios/web/public/web_state/web_state.h"
+
+namespace {
+// Prefix for print JavaScript command.
+const char kPrintCommandPrefix[] = "print";
+}
+
+PrintObserver::PrintObserver(web::WebState* web_state)
+ : web::WebStateObserver(web_state) {
+ web_state->AddScriptCommandCallback(
+ base::Bind(&PrintObserver::OnPrintCommand, base::Unretained(this)),
+ kPrintCommandPrefix);
+}
+
+PrintObserver::~PrintObserver() {
+ Detach();
+}
+
+void PrintObserver::WebStateDestroyed() {
+ Detach();
+}
+
+bool PrintObserver::OnPrintCommand(const base::DictionaryValue&,
+ const GURL&,
+ bool) {
+ base::scoped_nsobject<GenericChromeCommand> print_command(
+ [[GenericChromeCommand alloc] initWithTag:IDC_PRINT]);
+ [web_state()->GetView() chromeExecuteCommand:print_command];
+ return true;
+}
+
+void PrintObserver::Detach() {
+ if (web_state()) {
+ web_state()->RemoveScriptCommandCallback(kPrintCommandPrefix);
+ }
+}
« no previous file with comments | « ios/chrome/browser/web/print_observer.h ('k') | ios/chrome/browser/web/progress_indicator_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698