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 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;
return rv;
}

View file

@ -134,7 +134,8 @@ class PdfViewerUI::ResourceRequester
content::ResourceDispatcherHostImpl::Get()->InitializeURLRequest(
request.get(), content::Referrer(url, blink::WebReferrerPolicyDefault),
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::ForRequest(request.get());

View file

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

View file

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

View file

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

View file

@ -16,7 +16,7 @@
#include "content/public/renderer/render_view.h"
#include "native_mate/dictionary.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/WebFrameWidget.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(
const base::string16& name, v8::Local<v8::Object> options) {
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(
@ -145,9 +146,6 @@ void WebFrame::SetSpellCheckProvider(mate::Arguments* args,
void WebFrame::RegisterURLSchemeAsSecure(const std::string& scheme) {
// 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) {
@ -200,7 +198,10 @@ void WebFrame::RegisterURLSchemeAsPrivileged(const std::string& scheme,
void WebFrame::InsertText(const std::string& text) {
web_frame_->frameWidget()
->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) {
@ -216,7 +217,7 @@ void WebFrame::ExecuteJavaScript(const base::string16& code,
std::unique_ptr<blink::WebScriptExecutionCallback> callback(
new ScriptExecutionCallback(completion_callback));
web_frame_->requestExecuteScriptAndReturnValue(
blink::WebScriptSource(code),
blink::WebScriptSource(blink::WebString::fromUTF16(code)),
has_user_gesture,
callback.release());
}

View file

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

View file

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

View file

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

View file

@ -126,13 +126,6 @@ void RendererClientBase::RenderFrameCreated(
// Allow access to file scheme from pdf viewer.
blink::WebSecurityPolicy::addOriginAccessWhitelistEntry(
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) {

View file

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