0

I'm working with the JDE 7.1 in BrowserField2Demo and want to know how to intercept the "pre-load" event. The "OLD" BrowserFieldDemo had events such as "Event.EVENT_URL_REQUESTED" that would allow URL pre-load manipulations. Where do these events happen with "BrowserField2"?

Example: If the URL requested was "http://www.bing.com/" and I wished to re-direct it to "http://www.google.com/" where does this "pre-load" event happen?

Here is my code after a failed attempt which doesn't work:


private BrowserField _browserField;    
private boolean _documentLoaded = false;
private BrowserFieldRequest _request;


/**
 * Creates a new BrowserFieldScreen object
 * @param request The URI of the content to display in this BrowserFieldScreen
 * @param enableScriptMenu True if a context menu is to be created for this BrowserFieldScreen instance, false otherwise
 */
public BrowserFieldScreen(BrowserFieldRequest request, boolean enableScriptMenu)
{    
    super(Screen.HORIZONTAL_SCROLL);

    BrowserFieldConfig config = new BrowserFieldConfig();  
    config.setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE);
    config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);
    config.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
    config.setProperty(BrowserFieldConfig.CONTROLLER, controller);
    _browserField = new BrowserField(config);
    add(_browserField);
    _request = request;        
}    


ProtocolController controller = new ProtocolController(_browserField)    
{    
    public void handleNavigationRequest(BrowserFieldRequest request) throws Exception    
    {    
        InputConnection inputConnection = handleResourceRequest(request);    
        _browserField.displayContent(inputConnection, request.getURL());    
    }    
};

What I see is that at the first time the handleNavigationRequest gets called is that it crashes with the error message saying

Error request content for google.com error message null

with a CLOSE button. Then nothing happens.

Nate
  • 31,017
  • 13
  • 83
  • 207
user386093
  • 67
  • 8
  • You could try [something like this answer, that uses ProtocolController](http://stackoverflow.com/a/11927341/119114). You could switch the URL being requested. – Nate Mar 06 '13 at 06:04
  • Thanks again Nate! I value your experience with my questions. – user386093 Mar 06 '13 at 14:41
  • Ok, I copied the code from that link you suggested but I get an error when I run it on my Torch 9850. >> I can't post code because it's too long << What happens when I use it is an error message shows: Error requesting content for: http://google.com Error message null Any suggestion what I'm doing wrong? – user386093 Mar 06 '13 at 14:50
  • `public BrowserFieldScreen(BrowserFieldRequest request, boolean enableScriptMenu) { super(Screen.HORIZONTAL_SCROLL); BrowserFieldConfig config = new BrowserFieldConfig(); config.setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE); config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE); config.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER); config.setProperty(BrowserFieldConfig.CONTROLLER, controller); _browserField = new BrowserField(config); add(_browserField); _request = request; }` – user386093 Mar 06 '13 at 14:54
  • `ProtocolController controller = new ProtocolController(_browserField) { public void handleNavigationRequest(BrowserFieldRequest request) throws Exception { InputConnection inputConnection = handleResourceRequest(request); _browserField.displayContent(inputConnection, request.getURL()); } };` – user386093 Mar 06 '13 at 14:55
  • try using the **edit** link and posting the code into your question, instead of into the comments. thanks – Nate Mar 06 '13 at 16:31
  • **What** doesn't work about the code you posted? It doesn't ever call `handleNavigationRequest()`? It doesn't redirect the URLs? In the code you show, `handleNavigationRequest()` isn't attempting to change the URL. It's passing the original URL on, unmodified. You also don't ever call `_browserField.requestContent(_request);`, so is the problem that you're just not seeing anything happen? Please be specific. Thanks. – Nate Mar 06 '13 at 21:48
  • Sorry about the lack of defining the problem. What I see is that at the first time the handleNavigationRequest gets called is that it crashes with the error message saying "Error request content for google.com error message null" with a button. Then nothing happens. Where should the `_browserField.requestContent(_requests);` be placed? I must have missed that in the sample code I was ripping. – user386093 Mar 06 '13 at 22:36
  • Ok, if you're getting the `handleNavigationRequest()` callback, then that means that `requestContent()` **is** being called. If you haven't modified the sample code, I think it's called automatically when the screen loads (in `onUiEngineAttached()`). So, that's not the problem. I'm on my Mac now, so I can't run in the sims ... I'll try to double check the rest of your code later. – Nate Mar 06 '13 at 22:51
  • Ok, I see that maybe the call is originating from `BrowserField2Demo() { try { BrowserFieldRequest request = new BrowserFieldRequest("http://google.com"); _browserScreen = new BrowserFieldScreen(request, true); extendJavaScript(_browserScreen.getBrowserField()); pushScreen(_browserScreen); } catch(Exception e) { errorDialog("An error occurred, exiting Webfilter: " + e.toString(), true); } }` Again, thanks for you help with my problem. – user386093 Mar 06 '13 at 23:28
  • 1
    I also have the problem reference with the code more clearly posted at: http://supportforums.blackberry.com/t5/Java-Development/BrowserField2-handleNavigation-event/td-p/2214251 which maybe easier to read. – user386093 Mar 06 '13 at 23:32
  • I figured out a working solution and posted it at: http://supportforums.blackberry.com/t5/Java-Development/BrowserField2-handleNavigation-event/td-p/2214251 – user386093 Mar 07 '13 at 19:20
  • Could you paste the solution you posted on supportforums.blackberry.com here, too, as an **answer**? and then, mark that as the correct answer? you'll get some points for doing so, and help others find the solution later, if blackberry.com links go stale. thanks. – Nate Mar 08 '13 at 05:01

0 Answers0