Fix blink API changes

This commit is contained in:
Cheng Zhao 2017-04-11 16:18:40 +09:00
parent 8634f37dfc
commit 481b04358e
11 changed files with 42 additions and 49 deletions

View file

@ -950,7 +950,7 @@ void WebContents::NavigationEntryCommitted(
int64_t WebContents::GetID() const { int64_t WebContents::GetID() const {
int64_t process_id = web_contents()->GetRenderProcessHost()->GetID(); int64_t process_id = web_contents()->GetRenderProcessHost()->GetID();
int64_t routing_id = web_contents()->GetRoutingID(); int64_t routing_id = web_contents()->GetRenderViewHost()->GetRoutingID();
int64_t rv = (process_id << 32) + routing_id; int64_t rv = (process_id << 32) + routing_id;
return rv; return rv;
} }

View file

@ -134,7 +134,8 @@ class PdfViewerUI::ResourceRequester
content::ResourceDispatcherHostImpl::Get()->InitializeURLRequest( content::ResourceDispatcherHostImpl::Get()->InitializeURLRequest(
request.get(), content::Referrer(url, blink::WebReferrerPolicyDefault), request.get(), content::Referrer(url, blink::WebReferrerPolicyDefault),
false, // download. false, // download.
render_process_id, render_view_id, render_frame_id, resource_context); render_process_id, render_view_id, render_frame_id,
content::PREVIEWS_OFF, resource_context);
content::ResourceRequestInfoImpl* info = content::ResourceRequestInfoImpl* info =
content::ResourceRequestInfoImpl::ForRequest(request.get()); content::ResourceRequestInfoImpl::ForRequest(request.get());

View file

@ -14,6 +14,8 @@
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "third_party/WebKit/public/platform/WebInputEvent.h" #include "third_party/WebKit/public/platform/WebInputEvent.h"
#include "third_party/WebKit/public/platform/WebMouseEvent.h"
#include "third_party/WebKit/public/platform/WebMouseWheelEvent.h"
#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
#include "third_party/WebKit/public/web/WebFindOptions.h" #include "third_party/WebKit/public/web/WebFindOptions.h"
#include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/clipboard.h"
@ -148,12 +150,14 @@ bool Converter<blink::WebInputEvent>::FromV8(
mate::Dictionary dict; mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict)) if (!ConvertFromV8(isolate, val, &dict))
return false; return false;
if (!dict.Get("type", &out->type)) blink::WebInputEvent::Type type;
if (!dict.Get("type", &type))
return false; return false;
out->setType(type);
std::vector<blink::WebInputEvent::Modifiers> modifiers; std::vector<blink::WebInputEvent::Modifiers> modifiers;
if (dict.Get("modifiers", &modifiers)) if (dict.Get("modifiers", &modifiers))
out->modifiers = VectorToBitArray(modifiers); out->setModifiers(VectorToBitArray(modifiers));
out->timeStampSeconds = base::Time::Now().ToDoubleT(); out->setTimeStampSeconds(base::Time::Now().ToDoubleT());
return true; return true;
} }
@ -174,19 +178,19 @@ bool Converter<blink::WebKeyboardEvent>::FromV8(
ui::KeyboardCode keyCode = atom::KeyboardCodeFromStr(str, &shifted); ui::KeyboardCode keyCode = atom::KeyboardCodeFromStr(str, &shifted);
out->windowsKeyCode = keyCode; out->windowsKeyCode = keyCode;
if (shifted) if (shifted)
out->modifiers |= blink::WebInputEvent::ShiftKey; out->setModifiers(out->modifiers() | blink::WebInputEvent::ShiftKey);
ui::DomCode domCode = ui::UsLayoutKeyboardCodeToDomCode(keyCode); ui::DomCode domCode = ui::UsLayoutKeyboardCodeToDomCode(keyCode);
out->domCode = static_cast<int>(domCode); out->domCode = static_cast<int>(domCode);
ui::DomKey domKey; ui::DomKey domKey;
ui::KeyboardCode dummy_code; ui::KeyboardCode dummy_code;
int flags = atom::WebEventModifiersToEventFlags(out->modifiers); int flags = atom::WebEventModifiersToEventFlags(out->modifiers());
if (ui::DomCodeToUsLayoutDomKey(domCode, flags, &domKey, &dummy_code)) if (ui::DomCodeToUsLayoutDomKey(domCode, flags, &domKey, &dummy_code))
out->domKey = static_cast<int>(domKey); out->domKey = static_cast<int>(domKey);
if ((out->type == blink::WebInputEvent::Char || if ((out->type() == blink::WebInputEvent::Char ||
out->type == blink::WebInputEvent::RawKeyDown)) { out->type() == blink::WebInputEvent::RawKeyDown)) {
// Make sure to not read beyond the buffer in case some bad code doesn't // Make sure to not read beyond the buffer in case some bad code doesn't
// NULL-terminate it (this is called from plugins). // NULL-terminate it (this is called from plugins).
size_t text_length_cap = blink::WebKeyboardEvent::textLengthCap; size_t text_length_cap = blink::WebKeyboardEvent::textLengthCap;
@ -218,20 +222,20 @@ v8::Local<v8::Value> Converter<content::NativeWebKeyboardEvent>::ToV8(
v8::Isolate* isolate, const content::NativeWebKeyboardEvent& in) { v8::Isolate* isolate, const content::NativeWebKeyboardEvent& in) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
if (in.type == blink::WebInputEvent::Type::RawKeyDown) if (in.type() == blink::WebInputEvent::Type::RawKeyDown)
dict.Set("type", "keyDown"); dict.Set("type", "keyDown");
else if (in.type == blink::WebInputEvent::Type::KeyUp) else if (in.type() == blink::WebInputEvent::Type::KeyUp)
dict.Set("type", "keyUp"); dict.Set("type", "keyUp");
dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.domKey)); dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.domKey));
dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString( dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString(
static_cast<ui::DomCode>(in.domCode))); static_cast<ui::DomCode>(in.domCode)));
using Modifiers = blink::WebInputEvent::Modifiers; using Modifiers = blink::WebInputEvent::Modifiers;
dict.Set("isAutoRepeat", (in.modifiers & Modifiers::IsAutoRepeat) != 0); dict.Set("isAutoRepeat", (in.modifiers() & Modifiers::IsAutoRepeat) != 0);
dict.Set("shift", (in.modifiers & Modifiers::ShiftKey) != 0); dict.Set("shift", (in.modifiers() & Modifiers::ShiftKey) != 0);
dict.Set("control", (in.modifiers & Modifiers::ControlKey) != 0); dict.Set("control", (in.modifiers() & Modifiers::ControlKey) != 0);
dict.Set("alt", (in.modifiers & Modifiers::AltKey) != 0); dict.Set("alt", (in.modifiers() & Modifiers::AltKey) != 0);
dict.Set("meta", (in.modifiers & Modifiers::MetaKey) != 0); dict.Set("meta", (in.modifiers() & Modifiers::MetaKey) != 0);
return dict.GetHandle(); return dict.GetHandle();
} }
@ -443,7 +447,7 @@ v8::Local<v8::Value> Converter<blink::WebCache::ResourceTypeStat>::ToV8(
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.Set("count", static_cast<uint32_t>(stat.count)); dict.Set("count", static_cast<uint32_t>(stat.count));
dict.Set("size", static_cast<double>(stat.size)); dict.Set("size", static_cast<double>(stat.size));
dict.Set("liveSize", static_cast<double>(stat.liveSize)); dict.Set("liveSize", static_cast<double>(stat.decodedSize));
return dict.GetHandle(); return dict.GetHandle();
} }

View file

@ -51,13 +51,13 @@ SpellCheckClient::SpellCheckClient(const std::string& language,
SpellCheckClient::~SpellCheckClient() {} SpellCheckClient::~SpellCheckClient() {}
void SpellCheckClient::spellCheck( void SpellCheckClient::checkSpelling(
const blink::WebString& text, const blink::WebString& text,
int& misspelling_start, int& misspelling_start,
int& misspelling_len, int& misspelling_len,
blink::WebVector<blink::WebString>* optional_suggestions) { blink::WebVector<blink::WebString>* optional_suggestions) {
std::vector<blink::WebTextCheckingResult> results; std::vector<blink::WebTextCheckingResult> results;
SpellCheckText(base::string16(text), true, &results); SpellCheckText(text.utf16(), true, &results);
if (results.size() == 1) { if (results.size() == 1) {
misspelling_start = results[0].location; misspelling_start = results[0].location;
misspelling_len = results[0].length; misspelling_len = results[0].length;
@ -66,10 +66,8 @@ void SpellCheckClient::spellCheck(
void SpellCheckClient::requestCheckingOfText( void SpellCheckClient::requestCheckingOfText(
const blink::WebString& textToCheck, const blink::WebString& textToCheck,
const blink::WebVector<uint32_t>& markersInText,
const blink::WebVector<unsigned>& markerOffsets,
blink::WebTextCheckingCompletion* completionCallback) { blink::WebTextCheckingCompletion* completionCallback) {
base::string16 text(textToCheck); base::string16 text(textToCheck.utf16());
if (text.empty() || !HasWordCharacters(text, 0)) { if (text.empty() || !HasWordCharacters(text, 0)) {
completionCallback->didCancelCheckingText(); completionCallback->didCancelCheckingText();
return; return;

View file

@ -13,6 +13,10 @@
#include "native_mate/scoped_persistent.h" #include "native_mate/scoped_persistent.h"
#include "third_party/WebKit/public/web/WebSpellCheckClient.h" #include "third_party/WebKit/public/web/WebSpellCheckClient.h"
namespace blink {
struct WebTextCheckingResult;
}
namespace atom { namespace atom {
namespace api { namespace api {
@ -27,15 +31,13 @@ class SpellCheckClient : public blink::WebSpellCheckClient {
private: private:
// blink::WebSpellCheckClient: // blink::WebSpellCheckClient:
void spellCheck( void checkSpelling(
const blink::WebString& text, const blink::WebString& text,
int& misspelledOffset, int& misspelledOffset,
int& misspelledLength, int& misspelledLength,
blink::WebVector<blink::WebString>* optionalSuggestions) override; blink::WebVector<blink::WebString>* optionalSuggestions) override;
void requestCheckingOfText( void requestCheckingOfText(
const blink::WebString& textToCheck, const blink::WebString& textToCheck,
const blink::WebVector<uint32_t>& markersInText,
const blink::WebVector<unsigned>& markerOffsets,
blink::WebTextCheckingCompletion* completionCallback) override; blink::WebTextCheckingCompletion* completionCallback) override;
void showSpellingUI(bool show) override; void showSpellingUI(bool show) override;
bool isShowingSpellingUI() override; bool isShowingSpellingUI() override;

View file

@ -16,7 +16,7 @@
#include "content/public/renderer/render_view.h" #include "content/public/renderer/render_view.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h" #include "native_mate/object_template_builder.h"
#include "third_party/WebKit/public/web/WebCache.h" #include "third_party/WebKit/public/platform/WebCache.h"
#include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFrameWidget.h" #include "third_party/WebKit/public/web/WebFrameWidget.h"
#include "third_party/WebKit/public/web/WebInputMethodController.h" #include "third_party/WebKit/public/web/WebInputMethodController.h"
@ -110,7 +110,8 @@ void WebFrame::SetLayoutZoomLevelLimits(double min_level, double max_level) {
v8::Local<v8::Value> WebFrame::RegisterEmbedderCustomElement( v8::Local<v8::Value> WebFrame::RegisterEmbedderCustomElement(
const base::string16& name, v8::Local<v8::Object> options) { const base::string16& name, v8::Local<v8::Object> options) {
blink::WebExceptionCode c = 0; blink::WebExceptionCode c = 0;
return web_frame_->document().registerEmbedderCustomElement(name, options, c); return web_frame_->document().registerEmbedderCustomElement(
blink::WebString::fromUTF16(name), options, c);
} }
void WebFrame::RegisterElementResizeCallback( void WebFrame::RegisterElementResizeCallback(
@ -145,9 +146,6 @@ void WebFrame::SetSpellCheckProvider(mate::Arguments* args,
void WebFrame::RegisterURLSchemeAsSecure(const std::string& scheme) { void WebFrame::RegisterURLSchemeAsSecure(const std::string& scheme) {
// TODO(pfrazee): Remove 2.0 // TODO(pfrazee): Remove 2.0
// Register scheme to secure list (https, wss, data).
blink::WebSecurityPolicy::registerURLSchemeAsSecure(
blink::WebString::fromUTF8(scheme));
} }
void WebFrame::RegisterURLSchemeAsBypassingCSP(const std::string& scheme) { void WebFrame::RegisterURLSchemeAsBypassingCSP(const std::string& scheme) {
@ -200,7 +198,10 @@ void WebFrame::RegisterURLSchemeAsPrivileged(const std::string& scheme,
void WebFrame::InsertText(const std::string& text) { void WebFrame::InsertText(const std::string& text) {
web_frame_->frameWidget() web_frame_->frameWidget()
->getActiveWebInputMethodController() ->getActiveWebInputMethodController()
->commitText(blink::WebString::fromUTF8(text), 0); ->commitText(blink::WebString::fromUTF8(text),
blink::WebVector<blink::WebCompositionUnderline>(),
blink::WebRange(),
0);
} }
void WebFrame::InsertCSS(const std::string& css) { void WebFrame::InsertCSS(const std::string& css) {
@ -216,7 +217,7 @@ void WebFrame::ExecuteJavaScript(const base::string16& code,
std::unique_ptr<blink::WebScriptExecutionCallback> callback( std::unique_ptr<blink::WebScriptExecutionCallback> callback(
new ScriptExecutionCallback(completion_callback)); new ScriptExecutionCallback(completion_callback));
web_frame_->requestExecuteScriptAndReturnValue( web_frame_->requestExecuteScriptAndReturnValue(
blink::WebScriptSource(code), blink::WebScriptSource(blink::WebString::fromUTF16(code)),
has_user_gesture, has_user_gesture,
callback.release()); callback.release());
} }

View file

@ -24,7 +24,6 @@ void AtomRenderFrameObserver::DidClearWindowObject() {
void AtomRenderFrameObserver::DidCreateScriptContext( void AtomRenderFrameObserver::DidCreateScriptContext(
v8::Handle<v8::Context> context, v8::Handle<v8::Context> context,
int extension_group,
int world_id) { int world_id) {
if (ShouldNotifyClient(world_id)) if (ShouldNotifyClient(world_id))
renderer_client_->DidCreateScriptContext(context, render_frame_); renderer_client_->DidCreateScriptContext(context, render_frame_);
@ -62,8 +61,7 @@ void AtomRenderFrameObserver::CreateIsolatedWorldContext() {
// Create initial script context in isolated world // Create initial script context in isolated world
blink::WebScriptSource source("void 0"); blink::WebScriptSource source("void 0");
frame->executeScriptInIsolatedWorld( frame->executeScriptInIsolatedWorld(World::ISOLATED_WORLD, &source, 1);
World::ISOLATED_WORLD, &source, 1, ExtensionGroup::MAIN_GROUP);
} }
bool AtomRenderFrameObserver::IsMainWorld(int world_id) { bool AtomRenderFrameObserver::IsMainWorld(int world_id) {

View file

@ -17,10 +17,6 @@ enum World {
ISOLATED_WORLD = 999 ISOLATED_WORLD = 999
}; };
enum ExtensionGroup {
MAIN_GROUP = 1
};
// Helper class to forward the messages to the client. // Helper class to forward the messages to the client.
class AtomRenderFrameObserver : public content::RenderFrameObserver { class AtomRenderFrameObserver : public content::RenderFrameObserver {
public: public:
@ -30,7 +26,6 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver {
// content::RenderFrameObserver: // content::RenderFrameObserver:
void DidClearWindowObject() override; void DidClearWindowObject() override;
void DidCreateScriptContext(v8::Handle<v8::Context> context, void DidCreateScriptContext(v8::Handle<v8::Context> context,
int extension_group,
int world_id) override; int world_id) override;
void WillReleaseScriptContext(v8::Local<v8::Context> context, void WillReleaseScriptContext(v8::Local<v8::Context> context,
int world_id) override; int world_id) override;

View file

@ -172,8 +172,7 @@ void AtomRendererClient::WillDestroyWorkerContextOnWorkerThread(
v8::Local<v8::Context> AtomRendererClient::GetContext( v8::Local<v8::Context> AtomRendererClient::GetContext(
blink::WebFrame* frame, v8::Isolate* isolate) { blink::WebFrame* frame, v8::Isolate* isolate) {
if (isolated_world()) if (isolated_world())
return frame->worldScriptContext( return frame->worldScriptContext(isolate, World::ISOLATED_WORLD);
isolate, World::ISOLATED_WORLD, ExtensionGroup::MAIN_GROUP);
else else
return frame->mainWorldScriptContext(); return frame->mainWorldScriptContext();
} }

View file

@ -126,13 +126,6 @@ void RendererClientBase::RenderFrameCreated(
// Allow access to file scheme from pdf viewer. // Allow access to file scheme from pdf viewer.
blink::WebSecurityPolicy::addOriginAccessWhitelistEntry( blink::WebSecurityPolicy::addOriginAccessWhitelistEntry(
GURL(kPdfViewerUIOrigin), "file", "", true); GURL(kPdfViewerUIOrigin), "file", "", true);
// Parse --secure-schemes=scheme1,scheme2
std::vector<std::string> secure_schemes_list =
ParseSchemesCLISwitch(switches::kSecureSchemes);
for (const std::string& secure_scheme : secure_schemes_list)
blink::WebSecurityPolicy::registerURLSchemeAsSecure(
blink::WebString::fromUTF8(secure_scheme));
} }
void RendererClientBase::RenderViewCreated(content::RenderView* render_view) { void RendererClientBase::RenderViewCreated(content::RenderView* render_view) {

View file

@ -8,6 +8,8 @@
#include <set> #include <set>
#include <sstream> #include <sstream>
using base::PlatformThreadRef;
#include "base/hash.h" #include "base/hash.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"