Skip to content

Commit

Permalink
Complete WebStateObserverBridge and follow Cocoa naming style.
Browse files Browse the repository at this point in the history
Adds remaining WebStateObserver methods to WebStateObserverBridge and
updates CRWWebStateObserver protocol methods to follow Cocoa style
guidelines for naming delegate methods.

Review URL: https://codereview.chromium.org/1079693002

Cr-Commit-Position: refs/heads/master@{#325277}
  • Loading branch information
jyquinn authored and Commit bot committed Apr 15, 2015
1 parent 61b860c commit 92d84da
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 57 deletions.
2 changes: 1 addition & 1 deletion components/favicon/ios/web_favicon_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ WebFaviconDriver::WebFaviconDriver(web::WebState* web_state,
WebFaviconDriver::~WebFaviconDriver() {
}

void WebFaviconDriver::FaviconURLUpdated(
void WebFaviconDriver::FaviconUrlUpdated(
const std::vector<web::FaviconURL>& candidates) {
DCHECK(!candidates.empty());
OnUpdateFaviconURL(FaviconURLsFromWebFaviconURLs(candidates));
Expand Down
2 changes: 1 addition & 1 deletion components/favicon/ios/web_favicon_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class WebFaviconDriver : public web::WebStateObserver,
~WebFaviconDriver() override;

// web::WebStateObserver implementation.
void FaviconURLUpdated(
void FaviconUrlUpdated(
const std::vector<web::FaviconURL>& candidates) override;

// Returns the active navigation entry's favicon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class LanguageDetectionController : public web::WebStateObserver {
// web::WebStateObserver implementation:
void PageLoaded(
web::PageLoadCompletionStatus load_completion_status) override;
void URLHashChanged() override;
void UrlHashChanged() override;
void HistoryStateChanged() override;
void WebStateDestroyed() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
StartLanguageDetection();
}

void LanguageDetectionController::URLHashChanged() {
void LanguageDetectionController::UrlHashChanged() {
StartLanguageDetection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,20 +362,20 @@ - (void)fetchPreviousAndNextElementsPresenceWithCompletionHandler:
#pragma mark -
#pragma mark CRWWebStateObserver

- (void)pageLoaded:(web::WebState*)webState {
- (void)webStateDidLoadPage:(web::WebState*)webState {
[self reset];
}

- (void)formActivity:(web::WebState*)webState
formName:(const std::string&)formName
fieldName:(const std::string&)fieldName
type:(const std::string&)type
value:(const std::string&)value
keyCode:(int)keyCode
error:(BOOL)error {
- (void)webState:(web::WebState*)webState
didRegisterFormActivityWithFormNamed:(const std::string&)formName
fieldName:(const std::string&)fieldName
type:(const std::string&)type
value:(const std::string&)value
keyCode:(int)keyCode
inputMissing:(BOOL)inputMissing {
web::URLVerificationTrustLevel trustLevel;
const GURL pageURL(webState->GetCurrentURL(&trustLevel));
if (error || trustLevel != web::URLVerificationTrustLevel::kAbsolute ||
if (inputMissing || trustLevel != web::URLVerificationTrustLevel::kAbsolute ||
!web::UrlHasWebScheme(pageURL) || !webState->ContentIsHTML()) {
[self reset];
return;
Expand Down
2 changes: 1 addition & 1 deletion ios/chrome/browser/autofill/form_suggestion_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ - (void)webStateDestroyed:(web::WebState*)webState {
[self detachFromWebState];
}

- (void)pageLoaded:(web::WebState*)webState {
- (void)webStateDidLoadPage:(web::WebState*)webState {
[self processPage:webState];
}

Expand Down
24 changes: 17 additions & 7 deletions ios/web/public/web_state/web_state_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "base/macros.h"

class GURL;

namespace web {

struct FaviconURL;
Expand Down Expand Up @@ -44,15 +46,15 @@ class WebStateObserver {
virtual void InsterstitialDismissed() {}

// Called on URL hash change events.
virtual void URLHashChanged() {}
virtual void UrlHashChanged() {}

// Called on history state change events.
virtual void HistoryStateChanged() {}

// Called on form submission. |user_interaction| is true if the user
// Called on form submission. |user_initiated| is true if the user
// interacted with the page.
virtual void DocumentSubmitted(const std::string& form_name,
bool user_interaction) {}
bool user_initiated) {}

// Called when the user is typing on a form field, with |error| indicating if
// there is any error when parsing the form field information.
Expand All @@ -62,10 +64,18 @@ class WebStateObserver {
const std::string& type,
const std::string& value,
int key_code,
bool error) {}

// Invoked when new FaviconURL candidates are received.
virtual void FaviconURLUpdated(const std::vector<FaviconURL>& candidates) {}
bool input_missing) {}

// Notifies the observer that the requestAutocomplete API was invoked from
// |source_url| for the form with the specified |form_name|.
// |user_initiated| indicates whether the API was invoked in response to a
// user interaction.
virtual void AutocompleteRequested(const GURL& source_url,
const std::string& form_name,
bool user_initiated) {}

// Invoked when new favicon URL candidates are received.
virtual void FaviconUrlUpdated(const std::vector<FaviconURL>& candidates) {}

// Invoked when the WebState is being destroyed. Gives subclasses a chance
// to cleanup.
Expand Down
74 changes: 56 additions & 18 deletions ios/web/public/web_state/web_state_observer_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,55 @@
#import "base/ios/weak_nsobject.h"
#import "ios/web/public/web_state/web_state_observer.h"

class GURL;

// Observes page lifecyle events from Objective-C. To use as a
// web::WebStateObserver, wrap in a web::WebStateObserverBridge.
// NOTE: This is far from complete. Add new methods as needed.
@protocol CRWWebStateObserver<NSObject>
@optional
// Invoked by WebStateObserverBridge::NavigationItemCommitted.
- (void)webState:(web::WebState*)webState
didCommitNavigationWithDetails:
(const web::LoadCommittedDetails&)load_details;

// Invoked by WebStateObserverBridge::PageLoaded.
- (void)webStateDidLoadPage:(web::WebState*)webState;

// Invoked by WebStateObserverBridge::InterstitialDismissed.
- (void)webStateDidDismissInterstitial:(web::WebState*)webState;

// Invoked by WebStateObserverBridge::UrlHashChanged.
- (void)webStateDidChangeURLHash:(web::WebState*)webState;

// Invoked by WebStateObserverBridge::HistoryStateChanged.
- (void)webStateDidChangeHistoryState:(web::WebState*)webState;

// Invoked by WebStateObserverBridge::DocumentSubmitted.
- (void)webState:(web::WebState*)webState
didSubmitDocumentWithFormNamed:(const std::string&)formName
userInitiated:(BOOL)userInitiated;

// Invoked by WebStateObserverBridge::FormActivityRegistered.
// TODO(ios): Method should take data transfer object rather than parameters.
- (void)webState:(web::WebState*)webState
didRegisterFormActivityWithFormNamed:(const std::string&)formName
fieldName:(const std::string&)fieldName
type:(const std::string&)type
value:(const std::string&)value
keyCode:(int)keyCode
inputMissing:(BOOL)inputMissing;

// Invoked by WebStateObserverBridge::AutocompleteRequested.
- (void)webState:(web::WebState*)webState
requestAutocompleteForFormNamed:(const std::string&)formName
sourceURL:(const GURL&)sourceURL
userInitiated:(BOOL)userInitiated;

// Invoked by WebStateObserverBridge::FaviconUrlUpdated.
- (void)webState:(web::WebState*)webState
didUpdateFaviconURLCandidates:
(const std::vector<web::FaviconURL>&)candidates;

// Page lifecycle methods. These are equivalent to the corresponding methods
// in web::WebStateObserver.
- (void)pageLoaded:(web::WebState*)webState;
- (void)documentSubmitted:(web::WebState*)webState
formName:(const std::string&)formName
userInteraction:(BOOL)userInteraction;
- (void)formActivity:(web::WebState*)webState
formName:(const std::string&)formName
fieldName:(const std::string&)fieldName
type:(const std::string&)type
value:(const std::string&)value
keyCode:(int)keyCode
error:(BOOL)error;
// Note: after |webStateDestroyed:| is invoked, the WebState being observed
// is no longer valid.
- (void)webStateDestroyed:(web::WebState*)webState;
Expand All @@ -51,18 +81,26 @@ class WebStateObserverBridge : public web::WebStateObserver {
id<CRWWebStateObserver> observer);
~WebStateObserverBridge() override;

// web::WebStateObserver:
// NOTE: This is far from complete. Add new methods as needed.
// web::WebStateObserver methods.
void NavigationItemCommitted(
const LoadCommittedDetails& load_details) override;
void PageLoaded(
web::PageLoadCompletionStatus load_completion_status) override;
void InsterstitialDismissed() override;
void UrlHashChanged() override;
void HistoryStateChanged() override;
void DocumentSubmitted(const std::string& form_name,
bool user_interaction) override;
bool user_initiated) override;
void FormActivityRegistered(const std::string& form_name,
const std::string& field_name,
const std::string& type,
const std::string& value,
int key_code,
bool error) override;
bool input_missing) override;
void AutocompleteRequested(const GURL& source_url,
const std::string& form_name,
bool user_initiated) override;
void FaviconUrlUpdated(const std::vector<FaviconURL>& candidates) override;
void WebStateDestroyed() override;

private:
Expand Down
91 changes: 73 additions & 18 deletions ios/web/web_state/web_state_observer_bridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,48 @@
WebStateObserverBridge::~WebStateObserverBridge() {
}

void WebStateObserverBridge::NavigationItemCommitted(
const web::LoadCommittedDetails& load_detatils) {
SEL selector = @selector(webState:didCommitNavigationWithDetails:);
if ([observer_ respondsToSelector:selector]) {
[observer_ webState:web_state()
didCommitNavigationWithDetails:load_detatils];
}
}

void WebStateObserverBridge::PageLoaded(
web::PageLoadCompletionStatus load_completion_status) {
SEL selector = @selector(pageLoaded:);
SEL selector = @selector(webStateDidLoadPage:);
if ([observer_ respondsToSelector:selector])
[observer_ webStateDidLoadPage:web_state()];
}

void WebStateObserverBridge::InsterstitialDismissed() {
SEL selector = @selector(webStateDidDismissInterstitial:);
if ([observer_ respondsToSelector:selector])
[observer_ webStateDidDismissInterstitial:web_state()];
}

void WebStateObserverBridge::UrlHashChanged() {
SEL selector = @selector(webStateDidChangeURLHash:);
if ([observer_ respondsToSelector:selector])
[observer_ webStateDidChangeURLHash:web_state()];
}

void WebStateObserverBridge::HistoryStateChanged() {
SEL selector = @selector(webStateDidChangeHistoryState:);
if ([observer_ respondsToSelector:selector])
[observer_ pageLoaded:web_state()];
[observer_ webStateDidChangeHistoryState:web_state()];
}

void WebStateObserverBridge::DocumentSubmitted(
const std::string& form_name, bool user_interaction) {
SEL selector = @selector(documentSubmitted:formName:userInteraction:);
void WebStateObserverBridge::DocumentSubmitted(const std::string& form_name,
bool user_initiated) {
SEL selector =
@selector(webState:didSubmitDocumentWithFormNamed:userInitiated:);
if ([observer_ respondsToSelector:selector]) {
[observer_ documentSubmitted:web_state()
formName:form_name
userInteraction:user_interaction];
[observer_ webState:web_state()
didSubmitDocumentWithFormNamed:form_name
userInitiated:user_initiated];
}
}

Expand All @@ -37,20 +65,47 @@
const std::string& type,
const std::string& value,
int key_code,
bool error) {
SEL selector =
@selector(formActivity:formName:fieldName:type:value:keyCode:error:);
bool input_missing) {
SEL selector = @selector(webState:
didRegisterFormActivityWithFormNamed:
fieldName:
type:
value:
keyCode:
inputMissing:);
if ([observer_ respondsToSelector:selector]) {
[observer_ formActivity:web_state()
formName:form_name
fieldName:field_name
type:type
value:value
keyCode:key_code
error:error];
[observer_ webState:web_state()
didRegisterFormActivityWithFormNamed:form_name
fieldName:field_name
type:type
value:value
keyCode:key_code
inputMissing:input_missing];
}
}

void WebStateObserverBridge::AutocompleteRequested(const GURL& source_url,
const std::string& form_name,
bool user_initiated) {
SEL selector = @selector(webState:
requestAutocompleteForFormNamed:
sourceURL:
userInitiated:);
if ([observer_ respondsToSelector:selector]) {
[observer_ webState:web_state()
requestAutocompleteForFormNamed:form_name
sourceURL:source_url
userInitiated:user_initiated];
}
}

void WebStateObserverBridge::FaviconUrlUpdated(
const std::vector<FaviconURL>& candidates) {
SEL selector = @selector(webState:didUpdateFaviconURLCandidates:);
if ([observer_ respondsToSelector:selector])
[observer_ webState:web_state() didUpdateFaviconURLCandidates:candidates];
}

void WebStateObserverBridge::WebStateDestroyed() {
SEL selector = @selector(webStateDestroyed:);
if ([observer_ respondsToSelector:selector]) {
Expand Down

0 comments on commit 92d84da

Please sign in to comment.