add api to webview
This commit is contained in:
parent
39e615ed87
commit
d162180196
12 changed files with 138 additions and 39 deletions
|
@ -225,7 +225,8 @@ WebContents::WebContents(content::WebContents* web_contents)
|
|||
}
|
||||
|
||||
WebContents::WebContents(v8::Isolate* isolate,
|
||||
const mate::Dictionary& options) {
|
||||
const mate::Dictionary& options)
|
||||
: request_id_(0) {
|
||||
// Whether it is a guest WebContents.
|
||||
bool is_guest = false;
|
||||
options.Get("isGuest", &is_guest);
|
||||
|
@ -441,12 +442,12 @@ void WebContents::FindReply(content::WebContents* web_contents,
|
|||
result.Set("requestId", request_id);
|
||||
result.Set("selectionArea", selection_rect);
|
||||
result.Set("finalUpdate", final_update);
|
||||
Emit("find-in-page-response", result);
|
||||
Emit("found-in-page", result);
|
||||
} else if (final_update) {
|
||||
result.Set("requestId", request_id);
|
||||
result.Set("matches", number_of_matches);
|
||||
result.Set("finalUpdate", final_update);
|
||||
Emit("find-in-page-response", result);
|
||||
Emit("found-in-page", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -926,25 +927,19 @@ void WebContents::ReplaceMisspelling(const base::string16& word) {
|
|||
web_contents()->ReplaceMisspelling(word);
|
||||
}
|
||||
|
||||
void WebContents::FindInPage(mate::Arguments* args) {
|
||||
int request_id;
|
||||
uint32 WebContents::FindInPage(mate::Arguments* args) {
|
||||
uint32 request_id = GetNextRequestId();
|
||||
base::string16 search_text;
|
||||
blink::WebFindOptions options;
|
||||
if (!args->GetNext(&request_id)) {
|
||||
args->ThrowError("Must provide a request id");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args->GetNext(&search_text)) {
|
||||
if (!args->GetNext(&search_text) || search_text.empty()) {
|
||||
args->ThrowError("Must provide a non-empty search content");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
args->GetNext(&options);
|
||||
|
||||
web_contents()->Find(request_id, search_text, options);
|
||||
web_contents()->GetMainFrame()
|
||||
->ActivateFindInPageResultForAccessibility(request_id);
|
||||
return request_id;
|
||||
}
|
||||
|
||||
void WebContents::StopFindInPage(content::StopFindAction action) {
|
||||
|
|
|
@ -110,7 +110,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
void Unselect();
|
||||
void Replace(const base::string16& word);
|
||||
void ReplaceMisspelling(const base::string16& word);
|
||||
void FindInPage(mate::Arguments* args);
|
||||
uint32 FindInPage(mate::Arguments* args);
|
||||
void StopFindInPage(content::StopFindAction action);
|
||||
|
||||
// Focus.
|
||||
|
@ -250,6 +250,10 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
|
||||
AtomBrowserContext* GetBrowserContext() const;
|
||||
|
||||
uint32 GetNextRequestId() {
|
||||
return ++request_id_;
|
||||
}
|
||||
|
||||
// Called when received a message from renderer.
|
||||
void OnRendererMessage(const base::string16& channel,
|
||||
const base::ListValue& args);
|
||||
|
@ -271,6 +275,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
// The type of current WebContents.
|
||||
Type type_;
|
||||
|
||||
// Request id used for findInPage request.
|
||||
uint32 request_id_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContents);
|
||||
};
|
||||
|
||||
|
|
|
@ -22,9 +22,10 @@ supportedWebViewEvents = [
|
|||
'page-title-updated'
|
||||
'page-favicon-updated'
|
||||
'enter-html-full-screen'
|
||||
'leave-html-full-screen',
|
||||
'media-started-playing',
|
||||
'media-paused',
|
||||
'leave-html-full-screen'
|
||||
'media-started-playing'
|
||||
'media-paused'
|
||||
'found-in-page'
|
||||
]
|
||||
|
||||
nextInstanceId = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue