summaryrefslogtreecommitdiffstats
path: root/pdf
diff options
context:
space:
mode:
authorraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-21 22:49:54 +0000
committerraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-21 22:49:54 +0000
commitf1ca5fcb4351c7d8cb4446c1dcc9dfedee69a5dd (patch)
tree885760c5463f1ca54c9aa929e073595a03eedb64 /pdf
parenta0c458629a0620ee65948645aa81c9a1dab43c55 (diff)
downloadchromium_src-f1ca5fcb4351c7d8cb4446c1dcc9dfedee69a5dd.zip
chromium_src-f1ca5fcb4351c7d8cb4446c1dcc9dfedee69a5dd.tar.gz
chromium_src-f1ca5fcb4351c7d8cb4446c1dcc9dfedee69a5dd.tar.bz2
Remove most references to VarPrivate/InstancePrivate from OOP PDF
This removes most references to VarPrivate and InstancePrivate from OOP PDF. These APIs are deprecated and we'd like to remove them. In most cases where they are currently used, we can simply switch to using a PostMessage to communicate with the extension. In the case of modal dialogs, these need to run synchronously from the perspective of the PDF engine and so PostMessage isn't sufficient. Right now these calls still use InstancePrivate but we should switch to using a specific private API eventually. BUG=303491 Review URL: https://codereview.chromium.org/286933011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271998 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'pdf')
-rw-r--r--pdf/out_of_process_instance.cc76
-rw-r--r--pdf/out_of_process_instance.h5
2 files changed, 55 insertions, 26 deletions
diff --git a/pdf/out_of_process_instance.cc b/pdf/out_of_process_instance.cc
index 006d2f3..ad1c656 100644
--- a/pdf/out_of_process_instance.cc
+++ b/pdf/out_of_process_instance.cc
@@ -24,6 +24,7 @@
#include "ppapi/c/dev/ppb_cursor_control_dev.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_rect.h"
+#include "ppapi/c/private/ppb_instance_private.h"
#include "ppapi/c/private/ppp_pdf.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
#include "ppapi/cpp/core.h"
@@ -117,6 +118,17 @@ const char* kJSGetAccessibilityJSONReplyType = "getAccessibilityJSONReply";
const char* kJSAccessibilityJSON = "json";
// Cancel the stream URL request (Plugin -> Page)
const char* kJSCancelStreamUrlType = "cancelStreamUrl";
+// Navigate to the given URL (Plugin -> Page)
+const char* kJSNavigateType = "navigate";
+const char* kJSNavigateUrl = "url";
+const char* kJSNavigateNewTab = "newTab";
+// Open the email editor with the given parameters (Plugin -> Page)
+const char* kJSEmailType = "email";
+const char* kJSEmailTo = "to";
+const char* kJSEmailCc = "cc";
+const char* kJSEmailBcc = "bcc";
+const char* kJSEmailSubject = "subject";
+const char* kJSEmailBody = "body";
const int kFindResultCooldownMs = 100;
@@ -191,10 +203,29 @@ void ScaleRect(float scale, pp::Rect* rect) {
rect->SetRect(left, top, right - left, bottom - top);
}
+// TODO(raymes): Remove this dependency on VarPrivate/InstancePrivate. It's
+// needed right now to do a synchronous call to JavaScript, but we could easily
+// replace this with a custom PPB_PDF function.
+pp::Var ModalDialog(const pp::Instance* instance,
+ const std::string& type,
+ const std::string& message,
+ const std::string& default_answer) {
+ const PPB_Instance_Private* interface =
+ reinterpret_cast<const PPB_Instance_Private*>(
+ pp::Module::Get()->GetBrowserInterface(
+ PPB_INSTANCE_PRIVATE_INTERFACE));
+ pp::VarPrivate window(pp::PASS_REF,
+ interface->GetWindowObject(instance->pp_instance()));
+ if (default_answer.empty())
+ return window.Call(type, message);
+ else
+ return window.Call(type, message, default_answer);
+}
+
} // namespace
OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
- : pp::InstancePrivate(instance),
+ : pp::Instance(instance),
pp::Find_Private(this),
pp::Printing_Dev(this),
pp::Selection_Dev(this),
@@ -497,10 +528,6 @@ void OutOfProcessInstance::DidChangeView(const pp::View& view) {
OnGeometryChanged(zoom_, old_device_scale);
}
-pp::Var OutOfProcessInstance::GetInstanceObject() {
- return pp::Var();
-}
-
pp::Var OutOfProcessInstance::GetLinkAtPosition(
const pp::Point& point) {
pp::Point offset_point(point);
@@ -807,12 +834,11 @@ void OutOfProcessInstance::NavigateTo(const std::string& url,
return;
}
}
- if (open_in_new_tab) {
- GetWindowObject().Call("open", url_copy);
- } else {
- GetWindowObject().GetProperty("top").GetProperty("location").
- SetProperty("href", url_copy);
- }
+ pp::VarDictionary message;
+ message.Set(kType, kJSNavigateType);
+ message.Set(kJSNavigateUrl, url_copy);
+ message.Set(kJSNavigateNewTab, open_in_new_tab);
+ PostMessage(message);
}
void OutOfProcessInstance::UpdateCursor(PP_CursorType_Dev cursor) {
@@ -885,17 +911,17 @@ void OutOfProcessInstance::GetDocumentPassword(
}
void OutOfProcessInstance::Alert(const std::string& message) {
- GetWindowObject().Call("alert", message);
+ ModalDialog(this, "alert", message, std::string());
}
bool OutOfProcessInstance::Confirm(const std::string& message) {
- pp::Var result = GetWindowObject().Call("confirm", message);
+ pp::Var result = ModalDialog(this, "confirm", message, std::string());
return result.is_bool() ? result.AsBool() : false;
}
std::string OutOfProcessInstance::Prompt(const std::string& question,
const std::string& default_answer) {
- pp::Var result = GetWindowObject().Call("prompt", question, default_answer);
+ pp::Var result = ModalDialog(this, "prompt", question, default_answer);
return result.is_string() ? result.AsString() : std::string();
}
@@ -908,15 +934,19 @@ void OutOfProcessInstance::Email(const std::string& to,
const std::string& bcc,
const std::string& subject,
const std::string& body) {
- std::string javascript =
- "var href = 'mailto:" + net::EscapeUrlEncodedData(to, false) +
- "?cc=" + net::EscapeUrlEncodedData(cc, false) +
- "&bcc=" + net::EscapeUrlEncodedData(bcc, false) +
- "&subject=" + net::EscapeUrlEncodedData(subject, false) +
- "&body=" + net::EscapeUrlEncodedData(body, false) +
- "';var temp = window.open(href, '_blank', " +
- "'width=1,height=1');if(temp) temp.close();";
- ExecuteScript(javascript);
+ pp::VarDictionary message;
+ message.Set(pp::Var(kType), pp::Var(kJSEmailType));
+ message.Set(pp::Var(kJSEmailTo),
+ pp::Var(net::EscapeUrlEncodedData(to, false)));
+ message.Set(pp::Var(kJSEmailCc),
+ pp::Var(net::EscapeUrlEncodedData(cc, false)));
+ message.Set(pp::Var(kJSEmailBcc),
+ pp::Var(net::EscapeUrlEncodedData(bcc, false)));
+ message.Set(pp::Var(kJSEmailSubject),
+ pp::Var(net::EscapeUrlEncodedData(subject, false)));
+ message.Set(pp::Var(kJSEmailBody),
+ pp::Var(net::EscapeUrlEncodedData(body, false)));
+ PostMessage(message);
}
void OutOfProcessInstance::Print() {
diff --git a/pdf/out_of_process_instance.h b/pdf/out_of_process_instance.h
index c4b241c..ada259f 100644
--- a/pdf/out_of_process_instance.h
+++ b/pdf/out_of_process_instance.h
@@ -23,8 +23,8 @@
#include "ppapi/cpp/graphics_2d.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/input_event.h"
+#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/private/find_private.h"
-#include "ppapi/cpp/private/instance_private.h"
#include "ppapi/cpp/private/uma_private.h"
#include "ppapi/cpp/private/var_private.h"
#include "ppapi/cpp/url_loader.h"
@@ -36,7 +36,7 @@ class TextInput_Dev;
namespace chrome_pdf {
-class OutOfProcessInstance : public pp::InstancePrivate,
+class OutOfProcessInstance : public pp::Instance,
public pp::Find_Private,
public pp::Printing_Dev,
public pp::Selection_Dev,
@@ -54,7 +54,6 @@ class OutOfProcessInstance : public pp::InstancePrivate,
virtual void HandleMessage(const pp::Var& message) OVERRIDE;
virtual bool HandleInputEvent(const pp::InputEvent& event) OVERRIDE;
virtual void DidChangeView(const pp::View& view) OVERRIDE;
- virtual pp::Var GetInstanceObject() OVERRIDE;
// pp::Find_Private implementation.
virtual bool StartFind(const std::string& text, bool case_sensitive) OVERRIDE;